【问题标题】:Session still exist after facebook logout in my application在我的应用程序中 facebook 注销后会话仍然存在
【发布时间】:2011-09-28 06:27:13
【问题描述】:

嗨,我正在使用facebook graph api 在我的codeigniter 应用程序中邀请朋友。如果我已经登录到 facebook,则会显示以下屏幕

如果我没有登录页面重定向到 facebook 登录页面,成功登录后重定向回上面的页面。一切正常。但问题是

1) i log in to facebook .  
2) i run my application and get the list of friends to invite (above view) . 
3)then i log out from facebook . 
4)then refresh (F5) my friends invite page .

异常发生,

部分异常

Error:FacebookApiException Object
(
    [result:protected] => Array
        (
            [error] => Array
                (
                    [message] => Error validating access token: The session is invalid because the user logged out.
                    [type] => OAuthException
                )

        )

    [message:protected] => Error validating access token: The session is invalid because the user logged out.
    [string:Exception:private] => 
    [code:protected] => 0
    [file:protected] => C:\xampp\htdocs\elephanti\application\frontend\libraries\connections\facebook.php
    [line:protected] => 530
    [trace:Exception:private] => Array

我的代码是

public function invite_friends()
{

    $fbconfig = array(
        'appId' => $this->co_config_items['fb_appid'],
        'secret' => $this->co_config_items['fb_secret'],
        'cookie' => true,
        'domain' => $this->ci->config->item('domain')
    );

    $this->ci->load->library('connections/facebook', $fbconfig);

    $facebook = new Facebook($fbconfig);

    $session = $facebook->getSession();    

    if (!isset($session)) {

        $url = $facebook->getLoginUrl(array(
                    'canvas' => 1,
                    'fbconnect' => 0
                ));

        echo "<script type='text/javascript'>top.location.href = '$url';</script>";

    } else {

        try {

            $uid = $facebook->getUser();  
            $me = $facebook->api('/me');

            $updated = date("l, F j, Y", strtotime($me['updated_time']));

        } catch (FacebookApiException $e) {

            echo "Error:" . print_r($e, true);
        }
    }
    $data=array('fb_appid'=>$this->co_config_items['fb_appid']);

    return $data;
}

异常打印来自

} catch (FacebookApiException $e) {

    echo "Error:" . print_r($e, true);
}

阻止

事情是在 if else 条件下 else 部分正在工作,但是当我从 facebook 注销时不应该有会话。但会话尚未清除,我在第一次和第二次时 var_dump 会话。

退出前

array(7) {
  ["session_key"]=>
  string(46) "2.AQC0otQQWydT6w0l.3600.1317193200.0-770398599"
  ["uid"]=>
  string(9) "770398599"
  ["expires"]=>
  int(1317193200)
  ["secret"]=>
  string(24) "E9oNYQCuQdggyp_pJyLnqA__"
  ["base_domain"]=>
  string(9) "localhost"
  ["access_token"]=>
  string(90) "140577549320080|2.AQC0otQQWydT6w0l.3600.1317193200.0-770398599|5ZoDt4wTt16ve0fgaj8m_X70ojw"
  ["sig"]=>
  string(32) "74a283a7cd2f4d62bb7739deaf65affc"
}

注销后刷新一次

array(7) {
  ["access_token"]=>
  string(90) "140577549320080|2.AQC0otQQWydT6w0l.3600.1317193200.1-770398599|C84xhtx_dnakmf-7oCZlb07FQL8"
  ["base_domain"]=>
  string(9) "localhost"
  ["expires"]=>
  string(10) "1317193200"
  ["secret"]=>
  string(24) "E9oNYQCuQdggyp_pJyLnqA__"
  ["session_key"]=>
  string(46) "2.AQC0otQQWydT6w0l.3600.1317193200.1-770398599"
  ["sig"]=>
  string(32) "6eedc49e4957708a551c4155ff8f57a6"
  ["uid"]=>
  string(9) "770398599"
}

在第二次刷新sessionNULL并重定向到登录页面并且工作正常,为什么第一次没有清除会话,请帮助。

更新

sessionNULL 之后,我打印session 并添加die,然后再次登录Facebook;

$session = $facebook->getSession();
打印_r($会话); 死;

事情是现在每次都给NULL,所以我想一个地方之后

 $session = $facebook->getSession();    

会话正在创建,我认为这就是为什么我在 second 时间得到正确结果的原因,会话从哪里改变?

我搜索并看到了类似的问题,但无法获得帮助。请帮忙........

【问题讨论】:

  • 您在第 3 步中退出 facebook 的具体操作是什么?
  • mm 我正在从 Facebook 注销。 , 在语法上不做任何事情。因为我没有在我的应用程序中这样做,只是通常注销。我认为会话会清除......请帮助
  • Facebook.com 在您注销时不会告诉每个与之有会话的网站。您的应用程序也必须将它们注销。你可以...

标签: php facebook session codeigniter facebook-graph-api


【解决方案1】:

尝试在用户注销时添加监听器;

FB.subscribe('auth.logout', function(response){
    // Do something to let your program know that the user is now logged out.
});

和/或,使用 FB.logout() 将您自己的 facebook 注销添加到您的网站。这应该会清除您的网站/s fb 会话并将它们从 facebook.com 中注销。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-21
    • 2011-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多