Token that does not expire in facebook api

1

I'm doing a sigle page. for which I am using facebook api graph to get the last 3 posts I made on my facebook page, I managed to get the .json with the post but it turns out that I have to generate a token every so often to keep access to the information of the api, I have read the documentation and I see that you can only generate 2-hour tokens that are commonly used for sessions through facebook and there is also the possibility of generating a token that lasts approximately 2 months, ... my question is if there is any way to generate a token that does not expire or in which way it could renew the token automatically so as not to be doing it manually -...

I send a greeting

    
asked by Luis Pastén 08.04.2017 в 04:08
source

1 answer

1

I think facebook does not support permanent tokens, only long-lasting as you say, the full explanation is here .

I got something interesting that might be useful for you

Having discovered that it is possible to generate an access token to Facebook pages that does not expire, here is a clear, step-by-step step for all those looking for the same:

  • Make sure you are the administrator of the FB page from which you want to get information
  • Create an FB application (it must be with the same user account as the admin page)
  • Go to the FB Graph API Explorer
  • In the top right, select the FB application that you created in the "Application" drop-down list
  • Click on "Get access token"
  • Be sure to add the manage_pages permission
  • Convert this short-term access token to a long-term access token with the call to GraphAPI 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>
  • Get the new long-term access token returned
  • Make a GraphAPI call to view your accounts with the new long-term access token https://graph.facebook.com/me/accounts?access_token=<tu token de acceso de larga duración>
  • Grab the access_token from the page that you will be pulling information
  • Lint the token to see that it is set to expire: never!
  • You should do that. With that you should have a token to Facebook pages that does not expire!

    Or if you use the PHP SDK you can try with

    // Set Extended Access Token
    $facebook->setExtendedAccessToken();
    
    // Get access short live access token
    $accessToken = $facebook->getAccessToken();
    
    // Exchange token
    $facebook->api('/oauth/access_token', 'POST',
        array(  
            'grant_type' => 'fb_exchange_token',           
            'client_id' => 'APP ID',
            'client_secret' => 'APP Secret',
            'fb_exchange_token' => $accessToken
        )
    );
    

    For more information look at the friendly source, I hope it helps you!

    SOURCE

        
    answered by 15.04.2017 в 08:16