4
votes

I am logging into Facebook from Javascript SDK. On Server side, I am using PHP SDK to handle authentication. I am using FacebookJavaScriptLoginHelper() function. The problem i'am facing is, after i logout, I get this error:

Fatal error: Uncaught exception 'Facebook\FacebookSDKException' with message 'Session has expired, or is not valid for this app.' in this line $session->validate('App_Id', 'Secret');

if (isset($_SESSION['token'])) {
$session = new FacebookSession($_SESSION['token']);
try {
    $session->validate('App_Id', 'Secret');
} catch(FacebookAuthorizationException $e) {
    unset($session);
    echo "Exception occured, code: " . $e->getCode();
    echo " with message: " . $e->getMessage();
}
}


if (!isset($session)) {
try {
    $helper = new FacebookJavaScriptLoginHelper();
    $session = $helper->getSession();        
    $_SESSION['token'] = $session->getToken();
} catch(FacebookRequestException $e) {
    unset($session);
    echo "Exception occured, code: " . $e->getCode();
    echo " with message: " . $e->getMessage();
}
}

Here are my two points of interest:

  • How to handle the session expire and refresh it when the user has logged in?
  • I get this FacebookAuthorizationException : "This authorization code has been used". When I go to previous page and comeback, this error disappears. I think it's because of the session transfer between javascript and php is not handled properly. Whats the correct way to solve this?

Since there are no proper docs for Facebook login, unable to find the solution. Any suggestions would be helpful.

1

1 Answers

0
votes

I would suggest you to use https://github.com/facebookgo

it's very easy to use and ready for implementation.