0
我的應用程序工作得很好,一切正常,但當用戶註銷或兩個小時後回來或更改密碼或刪除應用程序,然後嘗試再次添加它我得到這樣的錯誤與每個原因錯誤:如何驗證訪問令牌並獲取新的無效的?
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>';
}
?>
我嘗試設置爲在我嘗試授權任何內容之前將令牌設置爲null,但這種方式不起作用。 – Dido