How To: Facebook Access Token
I’m a big fan of the Facebook Graph API. It’s easy to use and well documented. Recently, the facebook feeds on a few of our client sites went down. Upon investigation, it appears that Facebook has changed the way data can be accessed through their API. Feed data can now only be retrieved using an authentication token. The process was relatively simple to set up, but not immediately straightforward.
Here’s what you need to do in order to get an authentication token:
- Go to http://www.facebook.com/developers, login to your facebook account, and add the developer app, if requested.
- Click the ‘add a new app’ button to create a new app.
- Give the app a name, keeping in mind facebook’s naming policies.
- After creating the app, you should end up at an admin panel with your new app information ready. Go to ‘https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=APP_ID&client_secret=APP_SECRET’ replacing APP_ID with your newly created app ID and APP_SECRET with your new app Secret, both of which are displayed on the application administration panel. If the credentials are correct, you will see your authentication token at that location.
- This token can now be used in order to retrieve data from a feed. For example: ‘https://www.facebook.com/PAGE_OR_USER_ACCOUNT/feed?access_token=ACCESS_TOKEN’, replace PAGE_OR_USER_ACCOUNT with the page id or user account name and ACCESS_TOKEN with the token you retrieved in step 4.
It’s that easy!
A few things to note:
- Your access token will change periodically, implying your Facebook data retrieval method will need to dynamically retrieve the access code from Facebook using the method in step 4.
- Facebook Apps can be url specific, or you can leave those fields blank and use this authentication method to retrieve public data from Facebook from multiple urls.
Visit www.glassfest.org to see how we recently implemented a Facebook feed into a client’s site design.