Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a Facebook access token for a page with no app or app secret

I am trying to automatically display wall posts from a Facebook page another website. I can use the Graph API explorer to get one manually. When I use the generated token in my code all is well. The problem is the tokens expire quickly. It just isn't practical to get a new code several times a day. I know there is a way to request an access token programatically - in my case via PHP, but all the examples call for an app secret. Since this is a page and not an app, there is no secret.

I have tried this:

https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=MY_CLIENT_ID&redirect_uri=http%3A%2F%2FMY_SITE_URL&scope=user_status

What I get back is this:

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

I have tried using Fiddler to intercept the call from the Graph API explorer to see what I need in my code file, but haven't had any luck.

like image 989
Mike K. Avatar asked Jun 28 '12 03:06

Mike K.


People also ask

How do I get a short live access token on Facebook?

Go to https://developers.facebook.com/tools/explorer/ and select your app from the first drop down menu, in the left. Click on the button "Get access token", and in the "Select Permissions" window, click in "Extended Permissions" and check manage_pages and publish_stream, and click in "Get Access Token" blue button.


1 Answers

  1. Use the app-id to build this link to authorize the managing of pages https://www.facebook.com/dialog/oauth?client_id=MY_CLIENT_ID&redirect_uri=MY_SITE_URL&scope=manage_pages&response_type=token

  2. Exchange token for perm (longer token)
    https://graph.facebook.com/oauth/access_token?client_id=MY_CLIENT_ID&client_secret=MY_CLIENT_SECRET&grant_type=fb_exchange_token&fb_exchange_token=(from link1)

  3. Visit this page, find the PAGE you want to post and copy the new access_token https://graph.facebook.com/me/accounts?access_token= (from link2)

  4. Use this last token (form link3) to post to page as app

  5. Take note as it will expire in 60 days. (FB no longer offering unlimited offline access token)

Edit (2013 Oct 24): 5th point no longer true, Page Access Tokens generated from long-lived User Tokens do not expire.

Edit (Feb 2016): Tokens now "usually" expire in 60 days but can be invalidated at any time.

like image 110
MPaulo Avatar answered Nov 26 '22 15:11

MPaulo