我的应用程序运行正常,一切正常但是当用户退出或两小时后回来或更改密码或删除应用程序然后尝试再次添加它我得到这样的错误,原因是每个错误:
Fatal error: Uncaught OAuthException: Error validating access token: The session is invalid because the user logged out. thrown in /home/user/public_html/new_fb_app/src/base_facebook.php on line 1028
此外,如果我尝试刷新此错误后,应用程序将正常工作。所以我猜这与试图使用最后一个访问令牌(无效)的应用程序有关。
这是我的代码:
<?php
$user = null; //facebook user uid
try{
include_once "src/facebook.php";
}
catch(Exception $o){
echo '<pre>';
print_r($o);
echo '</pre>';
}
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'my appId',
'secret' => 'my app secret',
'fileUpload' => true
));
// Get User ID
$user = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => 'read_stream, publish_stream, photo_upload, user_photos'
)
);
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$access_token = $facebook->getAccessToken();
} catch (FacebookApiException $e) {
//you should use error_log($e); instead of printing the info on browser
d($e); // d is a debug function defined at the end of this file
$user = null;
}
}
if (!$user) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
function d($d){
echo '<pre>';
print_r($d);
echo '</pre>';
}
?>
答案 0 :(得分:0)
用户退出时清空Cookie或会话?