How can long-lived access token be retrieved for a page via graph explorer?

試著忘記壹切 提交于 2019-12-08 11:54:00

问题


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:

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

  2. Using this token, Get the list of pages/apps-

    $facebook->api("/USER_ID/accounts"); 
    
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!