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.
@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:
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