Generate "never-expire" access token for Facebook Page

You can generate never expiring access token without coding, following this instructions:

  1. Open graph Explorer: https://developers.facebook.com/tools/explorer/.
  2. Choose your application from the right corner dropdown.
  3. From "Get Token" dropdown choose your Fan Page.
  4. Click on submit button to generate token.
  5. From the left side on "Search for a field" enter access_token and click submit again. Copy this token from the main window.
  6. Open https://developers.facebook.com/tools/debug/accesstoken and paste token here. Click "Debug".
  7. Click the button "Extend Access Token". This will generate never expiring token.

This is the code that I use to generate "Never" expire access token using PHP SDK:

$facebook = new \Facebook\Facebook([
  'app_id' => '{app-id}',
  'app_secret' => '{app-secret}',
  'default_graph_version' => 'v2.10',
  'default_access_token' => '{access-token}'
]);

// Exchange token
$token = $facebook->post('/oauth/access_token',
    array(  
        'grant_type' => 'fb_exchange_token',           
        'client_id' => 'APP ID',
        'client_secret' => 'APP Secret',
        'fb_exchange_token' => 'access Token'
    )
);
$token = $token->getDecodedBody();
$token = $token['access_token'];

echo $token;

I echo the access token and then debug it using the access token debugger. The result should be: Expires: Never.

References from the Documentation:

  • Set Extended Token
  • Expiration and Extending Tokens
  • Extending Page Access Tokens

Tags:

Facebook