2

I am trying to loading a facebook feed from my webpage using:

https://graph.facebook.com/177610425663218/feed

For this I got an access token from the Graph Explorer. The problem is that the token keeps running out:

Error validating access token: Session has expired at unix time ...

I know I could create a OAuth login to get a new token but I would like to show the feed on a webpage. I don't want to OAuth all visitors of the page. How do I get an constant access token for my site feed?

PiTheNumber
  • 22,828
  • 17
  • 107
  • 180

3 Answers3

6

You can easily get an access token. Just create an app and login using app_id and app_secret:

$response = file_get_contents('https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=some_app_id&client_secret=the_appsecret');
$token = str_replace('access_token=', '', $response);

Works for me.

PiTheNumber
  • 22,828
  • 17
  • 107
  • 180
  • when feeding FacebookSession the token and executing a request I get: "An active access token must be used to query information about the current user." – dev4life Dec 08 '14 at 03:43
  • @user2070775 please create a new question for your problem. otherwise you won't get any help. – PiTheNumber Dec 08 '14 at 08:46
1

I don't think you can, it looks like they are deprecating the offline_access permission. Further down in the page it mentions extending the current token by 60 days. Perhaps that may help?

TWith2Sugars
  • 3,384
  • 2
  • 26
  • 43
  • Can't I use my facebook account to generate a new access_token using php? Something like `file_get_content('facebook/login/getToken?username=bla&password=blub')` – PiTheNumber Mar 12 '12 at 12:31
  • You could, but if you invalidate the token (change password etc) you'll need to generate a new one. – TWith2Sugars Mar 12 '12 at 13:45
1

Check out my post from a couple of days ago (look at me Updated section in the original post).

Displaying Facebook posts to non-Facebook users

Because the offline_access permission is being deprecated, you're going to have to programmatically swap out your token periodically (which does not require reauthorization). Hope that helps.

Community
  • 1
  • 1
Kory Sharp
  • 490
  • 3
  • 11