Long Lived access token Facebook Page [closed]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 10:17:23

问题


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:


  1. First of all, learn the basic concepts and the different kinds of the access tokens from here

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

  3. 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:

  1. Create an Application

  2. Create a Page (your account need to be "administrator" of the page)

  3. Associate the application to the Page (the same way you do it when you want to add a Page Tab to a Page)

  4. Get a short-lived access token with the permission "manage_pages" associated to your Application.

  5. https://graph.facebook.com/oauth/authorize?client_id=APP_ID&scope=manage_pages&redirect_uri=http://www.facebook.com/connect/login_success.html

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

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

  8. Convert your short-lived access token to a long-lived (extending access token):

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

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