Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending Facebook Page Access Token

i need to extend my facebook access token, I'm calling this:

https://graph.facebook.com/oauth/access_token? 
client_id={MY PAGE ID}&
client_secret={THE SECRET KEY OF MY APP}&
grant_type=fb_exchange_token&
fb_exchange_token={AN ACCESS TOKEN FOR MY PAGE}

and I'm getting this error:

   "error": {
      "message": "Error validating application. Cannot get application info due to a system error.",
      "type": "OAuthException",
      "code": 101
   }

I've seen a lot of problem with that access_token, but none answer relative to pages, idk why facebook use api that why... but is the way...

Thank you,

like image 281
Artur Couto Avatar asked Apr 17 '12 00:04

Artur Couto


People also ask

How long do Facebook access tokens last?

When your app uses Facebook Login to authenticate someone, it receives a User access token. If your app uses one of the Facebook SDKs, this token lasts for about 60 days. However, the SDKs automatically refresh the token whenever the person uses your app, so the tokens expire 60 days after last use.


1 Answers

To get a long-lived access token you need to follow those steps:

  1. Create an Application
  2. Create a Page (your account need to be "administrator" of the page)
  3. Associate the application to the Page (the same way you do it when you want to add a Page Tab to a Page)

    http://facebook.com/add.php?api_key=*YOUR_APP_ID*&pages=1&page=*YOUR_PAGE_ID*
    
  4. Get a short-lived access token with the permission "manage_pages" associated to your Application.

    https://graph.facebook.com/oauth/authorize?client_id=__APP_ID__&scope=manage_pages&redirect_uri=http://www.facebook.com/connect/login_success.html
    then
    https://graph.facebook.com/oauth/access_token?client_id=__APP_ID__&redirect_uri=http://www.facebook.com/connect/login_success.html&client_secret=__APP_SECRET__&code=__CODE_FROM_PREVIOUS_REQUEST__
    
  5. Using the Graph API Explorer with the request /me/accounts you can see the access tokens for each Pages that you are administrator. The problem is that those access token are short-lived.

  6. Convert your short-lived access token to a long-lived (extending access token):

    https://graph.facebook.com/oauth/access_token?client_id=_APP_ID_&client_secret=_APP_SECRET_&grant_type=fb_exchange_token&fb_exchange_token=_ACCESS_TOKEN_ON_STEP_4_
    
  7. You can now test your new access token with the Access Token Debugger.

like image 147
FR6 Avatar answered Sep 19 '22 14:09

FR6