Getting an access token for my facebook app
I know that this seems like something that has been answered before but we are really stuck and confused here! (after hours of research)
We have a server that needs to get the insights information of one of our pages automatically. I have created a facebook app and the user who is the admin of the page in question has given the app manage_pages and read_insights permission.
Now if I post to below link I get an access token but this does not work for reding the insights: (the access token is a relatively short string)
https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=APP_ID_HERE&client_secret=APP_SECRET_HERE
Now if I try this in the browser with me logged in as the admin of the page I get the right access token:
https://graph.facebook.com/oauth/authorize?client_id=[APP_ID]&response_type=token&grant_type=client_credentials&redirect_uri=[REDIRECT]&scope=read_insights,manage_pages
I then get the JSON by using this:
[PAGE_ID]/insights/[METRIC]/lifetime?access_token=[ACCESS_TOKEN]
Please help as I am new to the facebook API and really need to figure this out.
It seems like all the information out there is for asking for the user to login to get the access token but we want our server to collect insights of our own pages.
Thanks in advance!
There are two types of access tokens, one for users and another for specific pages (you act as the page when using a page access token).
After you get the user access token with manage_pages permissions, you can use that to get the page access token from https://graph.facebook.com/me/accounts?access_token=[USER_ACCESS_TOKEN] Then with that token you should be able to query the insights data.
There is no way to guarantee that the token will continue to work indefinitely (offline permission is being deprecated and those weren't really indefinite in practice either). When the token stops working, you need to go manually get a new token again.
链接地址: http://www.djcxy.com/p/70378.html上一篇: 持久的FB访问
下一篇: 为我的Facebook应用获取访问令牌