简体   繁体   中英

Checking if a perticular user is logged in to facebook

I am storing the facebook user id of a user when he is authorizing my app for the first time, and setting it as cookie until he explicitly not click log out from my site to keep them logged in. When user open my website again, I want to check if that user is still logged in to facebook. If no, I want to prompt him to log in to facebook to use complete features of my website. How can I check if that particular user is logged in to facebook using his facebook id?

If inside canvas page and using PHP SDK:

require_once("lib/facebook-sdk/facebook.php");
$facebook = new Facebook
(   array('appId'=>$fb_app_id, 'secret'=>$fb_app_secret, 'fileUpload'=>true)
);
if ($facebook->getUser()) // if current user has logged in
{   echo "Logged in";
}
else
{   echo "Not logged in";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM