How to obtain your Facebook application’s Access Token

There are FB APIs that require the usage of an application’s access token (e.g. sending an app to user FBAppReq, publishing the user score on an app)

Referring to the doc https://developers.facebook.com/docs/authentication/applications/, we can get the app’s access token by doing a GET on a particular URL with the appID and appSecret as the query string parameters.

Today, while I was writing code that publishes the user’s score to Facebook, as a quick and dirty “try my luck approach”, I specify the application access token with the “old school” format, i.e.  {appID} | {appSecret}  (i.e. 213123123|99999999999999999999 }.

To my surprise, it works.  ^_^

I have clarified with the team and notice that in practice both ways should work.

Having said that, my recommendation is:

  • for quick and dirty test, use the appID|appSecret as the app token
    if it works, then you are lucky and at least you can continue with the dev.
  • HOWEVER, in the final code, you should obtain and use the access token as in the “authenticating as an app” approach that FB explains in its documentation.

I had gone through the doc and notice that this app token will not get expired unless we reset the appSecret.

So, if needed, you can obtained the app’s access token and set this in the config file.
And if you are actually getting this at runtime, then by caching it (say in memcache), it won’t have much impact to the overall performance for your script.

This entry was posted in Development Tips and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *