How to get a Facebook access token for a page with no app or app secret

不问归期 提交于 2019-12-18 03:42:07

问题


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.


回答1:


For graph objects that are not private (public) you can use your app_id as an access_token.

Your app_id never changes so you don't ever have to renew it. The question is is the wall content yours?

If so you can easily use your app_id to accomplish this without having to request an access token everytime.

However, in order to have an app_id you need to create an application on facebook with a facebook developer account. As far as I understand there isnt a way to anonymously make request to the Graph API,




回答2:


  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.



来源:https://stackoverflow.com/questions/11237610/how-to-get-a-facebook-access-token-for-a-page-with-no-app-or-app-secret

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