The latest version of the Facebook PHP SDK makes it easy to get a long-lived access_token, giving you access to the user’s profile for up to 60 days, opposed to 1-2 hours with the regular access_token. The long-lived access_token can be used to perform tasks on the user’s behalf for long periods of time, for example, accessing check-in data for up to 60 days.

The setExtendedAccessToken() function exchanges the user’s short-lived access token for a long-lived one in just a few short lines of code:

<?php
$appId = 'aaaaaaaaaaaa';
$appSecret = 'bbbbbbbbbbbb';
// init facebook
$facebook = new Facebook( array( 'appId' => $appId, 'secret' => $appSecret ) );
// get user_id, 0 if not logged in
$user = $facebook->getUser();
// check if user is logged in
if ( $user ) {
// get long-lived access token
$facebook->setExtendedAccessToken();
$access_token = $facebook->getAccessToken();
}

The long-lived access_token means the user doesn’t need to login to your application for an extended period of time. In addition, using the long-lived access token with the manage_pages permission gives you access to page tokens that do not expire.

Note:

Just like short-lived access token, the long-lived token expires if the user changes their password, deauthorizes an app, or logs out. In these cases, the app should handle errors gracefully.