您好我在我的facebook graph api
申请中使用codeigniter
邀请朋友。如果我已经登录到Facebook,则会显示以下屏幕
如果我没有登录页面重定向到Facebook登录页面,suceesfuliy登录后重定向回上页。一切都很好。但问题是
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 .
exeption发生,
异常的一部分
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"
}
在第二次刷新中,session
为NULL
并重定向到登录页面并且工作正常,为什么会话未在第一时间清除,请帮助。
更新
在session
NULL
之后我打印session
并加注die
,然后再次登录到Facebook;
$ session = $ facebook-&gt; getSession();
的print_r($会议);
死;
事情现在每次都给NULL
,所以我想在
$session = $facebook->getSession();
会话正在创建,我想这就是为什么我在second
时间内得到正确的结果,会话正在改变?
我搜索并看到了类似的问题但无法获得帮助。请帮助..............
答案 0 :(得分:1)
尝试在用户注销时添加侦听器;
FB.subscribe('auth.logout', function(response){
// Do something to let your program know that the user is now logged out.
});
和/或使用FB.logout()将您自己的facebook登出添加到您的网站。这应该清除你的网站/ fb会话,并将它们从facebook.com注销。