Generate "never-expire" access token for Facebook Page
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.
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