问题
I want to allow an app to post as a page, so I used graph api to get access token to the page but it has one hour expiry.
Is there a way to retrieve long term access tokens via graph api?
P.S. I tried to use the endpoint for exchanging the short term access token with long term one and am getting OAuth error.
回答1:
You can have a never expiring token for your fan page. Follow the simple steps:
Get the admin's(i.e. yours) extended token (2 months validity). Go though the link to get the extended token. Works with perfection:
How to extend access token validity since offline_access deprecation
Using this token, 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:
You can getting 60 days access_token by following code.
$user = $facebook->getUser();
$facebook->setExtendedAccessToken(); //long-live access_token 60 days
$access_token = $facebook->getAccessToken();
来源:https://stackoverflow.com/questions/14128732/how-can-long-lived-access-token-be-retrieved-for-a-page-via-graph-explorer