Search code examples
phpyiifacebook-php-sdkyii-extensions

In yii, facebook opengraph return uid when user logout from facebook in another browser tab


I am working in yii 1.1 and have an extension yii-facebook-opengraph wrapper of php sdk 3.1.1

    $facebook_id = Yii::app()->facebook->getUser();
    if ($facebook_id) 
      { 
       // check that you get a Facebook ID before calling api()
       // now we know we have a Facebook Session,
       $user_info = Yii::app()->facebook->api('/me'); // so it's safe to call api()
       if ($user_info) 
       {
          // ...  code ...
       }
      }

the problem is when user login by facebook in one tab and logout from facebook in other tab then $facebook_id is still set. Why? and when tried to access user info, got error "Requires user session ". i have searched a lot and find something like

$facebook->getSession();

to get user session but this function is not available in yii-facebook-opengraph Please suggest me any solution.


Solution

  • Try:

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

    Where $fb is your instance of your $fb = new Facebook();