Generate "never-expire" access token for Facebook Page

Solution 1:

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.

Solution 2:

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

Solution 3:

  1. Generate long-lived token for admin of the fan page http://appdevresources.blogspot.sg/2012/11/extend-facebook-access-token-make-it.html (nice explanation with images)
  2. Generate long-lived token for fan page itself http://appdevresources.blogspot.sg/2012/11/retrieving-facebook-page-id-and.html
  3. Use token from 2) to post on the fan page's wall (no need for Facebook Login dialog)
  4. Resulted token will never expire (even if administrator of the fan page did log out)