How to get permanent access token in graph API

2020-06-19 03:13发布

I created an APP on Facebook and using graph API explorer, I selected my app from app drop down box, requested access token with manage_pages, offline_access and publish_stream permissions.

Using this access token, I was successfully able to post message on page using restfb APIs but when I log out, it starts throwing The session is invalid error.

I read on few posts that offline_access is deprecated. Could someone tell me how to obtain permanent access token?

Thanks

3条回答
smile是对你的礼貌
2楼-- · 2020-06-19 03:20

Looking at the docs at: https://developers.facebook.com/roadmap/offline-access-removal/ this is no longer possible.

Desktop applications will not be able to extend the life of an existing access_token and the user must login to facebook once the token has expired.

Otherwise, it is possible to request an access token with a longer expiration. Here are the directions: https://developers.facebook.com/roadmap/offline-access-removal/#extend_token

查看更多
女痞
3楼-- · 2020-06-19 03:29

What kind of Access Token do you need? There are three kinds, User AT, App AT and Page AT.

If you want User AT, it seems you are out of luck. I don't think it's possible anymore. You can only get to 60 days. However, if you need Page AT, you can get a permanent one. The difference is, Page Access Token only has access to a single facebook page.

Basically you need to get User Access Token first, with manage_pages permission. When you have one, you have to look at /{pageId}?fields=access_token for your page's id in Graph API.

For more info look at: facebook: permanent Page Access Token?

查看更多
家丑人穷心不美
4楼-- · 2020-06-19 03:40

you will not get any permanent access token as Facebook developer blog explains. you will be given 60 days long lived access token. Before the expiration Facebook will notify you about the expiry and then you can renew it or you can build your own custom control to get the notification on token expiration which you can fetch from Facebook API.

查看更多
登录 后发表回答