Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook API - Session still exists after user logout

I am using Facebook php-sdk in my iframe facebook app to get user login status. Right after I sign out using facebook Account > Log out link, the session is not destroyed yet. I must wait a few minutes before old session expires, then my app will again get the correct login status.

I expect the facebook to kill itself and the session when user signs out. How do I manually kill the session?

Here is my code:

$initParams = array(
  'appId'  => $conf['app_id'], 
  'secret' => $conf['secret_api_key'],
  'cookie' => TRUE,
);

$fb = new Facebook($initParams);
$fb->getSession();  // will return a session object eventhough user signed out!

SOLVED:

calling $fb->api('/me') will destroy the session if user has previously logged out. I've changed my code as following:

if ($session)
{
    try
    {
        $fbuid = $fb->getUser();
        $me = $fb->api('/me');
    }
    catch(FacebookApiException $e){}
}

If the API call is unsuccessful, $session will be set to NULL. Very weird behavior, I don't explain everything that is going on here but it solved my problem of having residual session object not being updated via getSession() method.

like image 840
flochtililoch Avatar asked Dec 22 '10 16:12

flochtililoch


People also ask

How long does Facebook Login last?

Data Access Expiration The expiration period for data access is 90 days, based on when the user was last active. When this 90-day period expires, the user can still access your app — that is, they are still authenticated — but your app can't access their data.

What is an api session on Facebook?

Facebook API is a bundle of solutions used as a primary way to get data in and out of the platform. It enables developers and app users to access the functionality of this network: user information, photos and videos, messages and more.


3 Answers

I'm using $fb->getUser() and what I did was almost identical with yours.

if ($fb->getUser())
{
    try
    {
        $me = $fb->api('/me');
    }
    catch(FacebookApiException $e){
        **$fb->destroySession();**
    }
}

I found that using only API to check whether FB is logged out or not sometimes is inconsistent, but with destroySession(), the session will surely be destroyed.

like image 81
Henson Avatar answered Oct 09 '22 20:10

Henson


if you are using the javascript FB.INIT calls on the login page, then set status to false from true.

details about the status attribute : http://developers.facebook.com/docs/reference/javascript/FB.init/

like image 37
tireof_fbscripting Avatar answered Oct 09 '22 20:10

tireof_fbscripting


Try finding the formatData function somewhere at LoginWindow (AS3) and find this line:

vars.redirect_uri = FacebookURLDefaults.LOGIN_SUCCESS_URL

Change the value for http://www.facebook.com/ and logout from that html page when logged in.

This is a temporary solution to logout if you are developer, not the end user.

like image 45
CesareoAguirre Avatar answered Oct 09 '22 18:10

CesareoAguirre