What is the PHP equivalent to Facebook's JS SDK of:
FB.getLoginStatus
I'm looking for something like:
$facebook->getLoginStatus()
However the above does not exist in the PHP library.
I have already tried both of these:
$this->facebook->api('/me');
$this->facebook->getUser();
Both do not work because PHP errors out, saying that I need a valid access_token and I am left with a blank page. I am unable to even check for a null response for the 2 methods above.
I simply need to check if a user is a returning user or not. Please help!
$facebook = new Facebook(array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
));
// Get User ID
$user = $facebook->getUser();
To check if the user is logged in on facebook (similar to FB.getLoginStatus) you need to do:
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
else {
$fbUrl = $facebook->getLoginUrl(array('scope' => '........'));
header("Location:".$fbUrl);
exit();
}
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With