Facebook-PHP SDK 3.0 : How do I store a session in the database once the user has logged in and provided the access?
I am using Facebook PHP SDK 3.0
I would like to know how could I store the session of the user in the database so that once the user provides access and logs in, I could store the access tokens in the database and use it next time so that the user doesn't require to log in again. Right now I am using the following code
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => SECRET,
开发者_StackOverflow'cookie' => true
));
$user = $facebook->getUser();
if(!$user)
{
$loginUrl = $facebook->getLoginUrl();
echo anchor($loginUrl,"login");
}
//print_r($_SESSION);
$user = $facebook->getUser();
if($user)
{
try
{
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
//print_r($user_profile);
}
catch (FacebookApiException $e)
{
error_log($e);
$user = null;
}
}
Any help appreciated thanks
Facebook access keys expire after a while. Even if you do store them, and they have not expired yet, they will not work if the user is not logged in. If you want to access the users Facebook account while the user is offline, you need the 'offline_access' permmission.
精彩评论