Generate "never-expire" access token for Facebook Page
Solution 1:
You can generate never expiring access token without coding, following this instructions:
- Open graph Explorer: https://developers.facebook.com/tools/explorer/.
- Choose your application from the right corner dropdown.
- From "Get Token" dropdown choose your Fan Page.
- Click on submit button to generate token.
- From the left side on "Search for a field" enter access_token and click submit again. Copy this token from the main window.
- Open https://developers.facebook.com/tools/debug/accesstoken and paste token here. Click "Debug".
- 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:
- 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)
- Generate long-lived token for fan page itself http://appdevresources.blogspot.sg/2012/11/retrieving-facebook-page-id-and.html
- Use token from 2) to post on the fan page's wall (no need for Facebook Login dialog)
- Resulted token will never expire (even if administrator of the fan page did log out)