1

To solve a problem detailed in a question on Stack Exchange Web Applications, I've written a little PHP script that given a page name and a proper access_token spits out the events created by that page as an iCal calendar file. Obviously this file is not supposed to be accessed by humans, but by for example Google Calendar for subscribing.

I created the access_token through the Facebook Graph Explorer and only later realized that it expires. So the question is: can I get a page access_token that does not expire? Failing that, can I get one with a really long expiration that?

If that is not possible - does anyone have a clue what to do? Manually providing an access_token once an hour doesn't feel very feasible.

Community
  • 1
  • 1
  • Get a long-lived user access token first (see https://developers.facebook.com/roadmap/offline-access-removal/). If you get your page access token using that, then the latter won’t expire by default. – CBroe Jul 21 '12 at 10:02
  • Thank you @CBroe! This hint put me on the right track. I've detailed my solution in an answer, see below. – Jobjörn Folkesson Jul 21 '12 at 19:43

2 Answers2

3

@CBroe put me on the right track, and @MPaulo helped me further. Here's how I explain the process in the beginning of the script file I've created to solve the problem described in the question I linked to at the beginning of my question above.


To begin with, you will need an access token. This is complicated stuff - getting a regular one is easy, but we want one that lasts permanently. As described in Scenario 5 here: https://developers.facebook.com/roadmap/offline-access-removal/ , we need to:

  1. Get a regular short-lived access token
  2. Exchange it for a long-lived access token
  3. Using our new access token, get a permanent page access token.

First, create a new Facebook app at https://developers.facebook.com/apps/ . It can be named whatever, it's not going to be really used. Fill in a domain - it doesn't matter which, just take one that shows simple HTML and doesn't do any redirects: I used my own static web page, http://jobjorn.se/ , but http://example.org/ may work too.

As instructed by MPaulo on Stack Overflow here: https://stackoverflow.com/a/11238327/564628 , use the app id - from your newly created app - and visit this page: https://www.facebook.com/dialog/oauth?client_id=MY_APP_ID&redirect_uri=MY_SITE_URL&scope=manage_pages&response_type=token Be sure to replace "MY_APP_ID" and "MY_SITE_URL".

Then, exchange your short-lived access token for a long-lived access token by visiting this page: https://graph.facebook.com/oauth/access_token?client_id=MY_APP_ID&client_secret=MY_APP_SECRET&grant_type=fb_exchange_token&fb_exchange_token=YOUR_ACCESS_TOKEN Be sure to replace "MY_APP_ID", "MY_APP_SECRET", and "YOUR_ACCESS_TOKEN" (the last being the access token you received from the first page)

Finally, get your page access token here: https://graph.facebook.com/me/accounts?access_token=YOUR_NEW_ACCESS_TOKEN Be sure to replace "YOUR_NEW_ACCESS_TOKEN" (the access token you recieved from the second page)

Paste it below. It should be permanent, but due to a bug it might only last two months - see https://developers.facebook.com/bugs/151056591697025 for details. It seems to have been fixed however. You can test it here: https://developers.facebook.com/tools/debug/access_token

Community
  • 1
  • 1
0

Create an app and use the app's credentials to authenticate. As long as you aren't reading user specific data, you don't need a user access_token.

cpilko
  • 11,792
  • 2
  • 31
  • 45