问题
I have a facebook page and i want the feeds of page. I am using graph api to get the access token but i have no idea how to convert that short-lived access token to long-lived 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=EXISTING_ACCESS_TOKEN
If above link is used to get the long live access token then from where i can get App_Secret
Help Me if i am going on wrong approach.
回答1:
First of all, learn the basic concepts and the different kinds of the access tokens from here
To get the extended User token (validity: 2months) use the code you have mentioned in the question.
You can get the app secret from the Apps page.
To get a never expiring token for your fan page. Follow the simple steps:
Using the user token you obtained through step 2, get the list of pages/apps-
$facebook->api("/USER_ID/accounts");
Get the never expiring access token for any page-
$facebook->api("/PAGE_ID?fields=access_token");
(You can use Facebook's Debug Tool to check the validity of the token.)
回答2:
To get a long-lived access token you need to follow those steps:
Create an Application
Create a Page (your account need to be "administrator" of the page)
Associate the application to the Page (the same way you do it when you want to add a Page Tab to a Page)
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
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.
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_
You can now test your new access token with the Access Token Debugger.
来源:https://stackoverflow.com/questions/14209658/long-lived-access-token-facebook-page