John Davidson

php - How to generate a permanent (never expiring) facebook user access token?

0 comments
Message:


As the title suggests im wondering how i could obtain a never expiring facebook user access token. Which i would need to create a page access token at a later date. I tried using their graph explorer tool but i could only make it go up to 2 months of expiry date and for my use case that wouldnt be ideal.


To shortly explain my use case, on our website im trying to implement a facebook sharing system where each user could share what they wanted i.e posts on their facebook page (we are not using facebook login and the user would just give acces from their own dev tool panel if thats the correct approach). I got this to work BUT only with a acces token that would expire in 2-3months. So a user having to re-authenicate with our service every 2-3 months isnt ideal and wouldnt really work for us. So is there a way i can refresh that token programtically or does the user have to give a new user access token every couple of months.


I have tried following this answer but with no luck Long Lived access token Facebook Page and many similar answers to this. There is also a suggestion that you should contact facebook if you want a never expiring access token which this user suggested Generate permanent access token Facebook API.


Now im wondering if it even is possible do that in 2021 and if there is anything i missed in regards how to generate said tokens or refresh them.


EDIT:


I used the following requests to get the extended access token.


https://graph.facebook.com/oauth/access_token?client_id=<your FB App ID >&client_secret=<your FB App secret>&grant_type=fb_exchange_token&fb_exchange_token=<your short-lived access token>

After i got the token i used


https://graph.facebook.com/me/accounts?access_token=<your long-lived access token> 

to get the extended access token.



My Answer:
Unfortunately, as of 2021, Facebook no longer allows the generation of permanent (never expiring) user access tokens. The longest duration for an access token is now 60 days.

You can use the method you mentioned to get a long-lived access token, which lasts for 60 days. After that, you will need to refresh the token by re-authenticating the user.

Alternatively, you can consider using Facebook's Page Access Tokens, which can be generated and refreshed programmatically without user intervention. This would allow you to continue posting on behalf of the user without the need for them to re-authenticate every 2-3 months.

Overall, it is recommended to follow Facebook's guidelines and use the available methods for obtaining and refreshing access tokens to ensure the security and integrity of your application.

Rate this post

3 of 5 based on 9429 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us