Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

graph - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...