Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook API OAuthException: “An unexpected error has occurred. Please retry your request later” when trying to retrieve a Page-specific access token

I want my app to be able to post status updates to a specific Page. I've got an application set up and retrieved its app ID, and I'm following the the “Page Login” section at the bottom of the Facebook authentication documentation here.

The first stage (user granting the app the manage_page permission) seems to work perfectly. I get redirected to a URL like this:

http://myapp.com/#access_token=ACCESS_TOKEN&expires_in=6483

The docs then say you should access the following:

https://graph.facebook.com/me/accounts?access_token=TOKEN_FROM_ABOVE

replacing TOKEN_FROM_ABOVE with the one returned by the previous request, and this should return “a list of all the Pages the user administers including Page specific access token for each Page”.

However, it doesn't. All I get is the following JSON response:

{
    "error": {
        "message": "An unexpected error has occurred. Please retry your request later.",
        "type": "OAuthException"
    }
}

What am I doing wrong? Could I have set something up incorrectly when creating the application? The error message is less than helpful, so any assistance would be much appreciated.

like image 398
Mark Bell Avatar asked Dec 02 '11 07:12

Mark Bell


3 Answers

I think I can shed a little more light on this.

I get this return often when making a request for the Page specific access tokens; failures on this call seem to be proportional to the number of Page's that are administered by the account for which the access token is for, so if you admin 100 pages, you will fail more often than if you have 1 pages, if you have a 5000 pages failures will happen more often than they don't.

This indicates that the failure is related to the response size, as the JSON returned can be very lengthy for large sets of Page's.

The fix for this is simple. Instead of requesting all of the Page's using

http://graph.facebook.com/me/accounts?access_token={admin access token}

use

http://graph.facebook.com/{page id}?fields=access_token&access_token={admin access token}

This will return the access token for just that page. Because the response is small you should experience Facebook server-side errors much less frequently. Since I switched I don't think I've ever experienced a failure and I make the call very often.

like image 92
walnutmon Avatar answered Oct 05 '22 13:10

walnutmon


Just suddenly started working this morning—no idea why.

like image 39
Mark Bell Avatar answered Oct 05 '22 11:10

Mark Bell


Try this... https://graph.facebook.com/me/accounts?access_token=TOKEN_FROM_ABOVE&expires_in=6483

like image 35
Ijat Melora Avatar answered Oct 05 '22 12:10

Ijat Melora