facebookapioauthfacebook-graph-api-v2.1

Facebook API - getting a token that never expires


i would like to generate a token that will never expire.

I have the "manage_pages" permission, and if the user has a "fanpage" the token will never expire.

But if the user doesnt have any fanpages created, the token will expire after 2 months.

I am using the newest api (PHP SDK).

This is my login:

$session = $helper->getSessionFromRedirect();

$token = $session->getToken();

And after that, i am doing something like that:

$accounts = new FacebookRequest($session, 
'GET', 
'/me/accounts?fields=picture,access_token,name');

Would be nice if some of you have an idea how i can get a token that never expires allthough the user hasnt a fanpage


Solution

  • The only Tokens that are valid forever are App Access Tokens and Extended Page Access Tokens. You can´t get a User Token that is valid forever, and you never need it anyway. If the user did not visit the App for more than 2 months, he most likely does not use the App anymore. You can refresh a User Token easily though, by using FB.getLoginStatus whenever the User visits your App.

    Here´s all you need to know about Access Tokens: