2012-01-30 76 views
5

我得到這個錯誤偶爾:錯誤驗證訪問令牌

Fatal error: Uncaught Exception: 190: Error validating access token: This may be because the user logged out or may be due to a system error. thrown in ..base_facebook.php on line 1053

的問題是,我得到它在隨機時間,沒有任何警告。我可以在幾周內沒有看到它,然後突然它會出現。解決方案?你可以等待它。它拋出這個錯誤約15分鐘,然後你可以刷新,它會讓你繼續你在做什麼。

我的問題是,這是我的目標?或者這是一個Facebook問題?如果有幫助,這是一個Facebook連接頁面。我做了研究,發現它可能是由FQL查詢造成的。但至少不會一致?看起來它完全是隨機的。無論如何,這是我的FQL查詢以防萬一。

$facebook->api(array('method' => 'fql.query','query' => "SELECT first_name,middle_name,last_name,email,affiliations FROM user WHERE uid=".$user)); 

這裏是線Base_Facebook的一○五二年至1071年,

protected function throwAPIException($result) { 
$e = new FacebookApiException($result); 
switch ($e->getType()) { 
    // OAuth 2.0 Draft 00 style 
    case 'OAuthException': 
    // OAuth 2.0 Draft 10 style 
    case 'invalid_token': 
    // REST server errors are just Exceptions 
    case 'Exception': 
    $message = $e->getMessage(); 
    if ((strpos($message, 'Error validating access token') !== false) || 
     (strpos($message, 'Invalid OAuth access token') !== false)) { 
    $this->setAccessToken(null); 
    $this->user = 0; 
    $this->clearAllPersistentData(); 
    } 
} 

throw $e; 

}

謝謝

+1

這只是一個[Facebook bug](https://developers.facebook.com/bugs/179301482177807)。 – brainondev 2012-06-11 16:53:09

+1

我想補充一點,如果用戶已經停用了他們的賬戶,這個錯誤也會發生。 – Chris 2012-12-26 06:43:02

回答

10

寫在 How-To: Handle expired access tokens (鏈接斷開)的開發人員博客文章

Access tokens for users can become invalid due to various reasons. In most cases, they can expire if it’s past the time specified by the expires field (by default access token have a 2 hour lifetime). What many developers do not realize is that an access token can also expire if a user changes her password, logs out or if she de-authorizes the app via the App Dashboard. It is very important that your apps handle such situations. If your access token expires, you need to reacquire a valid access token.

在我們可以使用offline_access權限獲取未過期的令牌(除非用戶與應用程序連接)之前,現在不允許使用此權限,請參閱Deprecation of Offline Access Permission以瞭解如何獲得access_token以及更長的到期時間。

更新:
作爲2012年8月Facebook的PHP-SDK have added simple way of extending access_token(見How to extend access token validity since offline_access deprecation有詳細介紹)

更新2: 注意,從Facebook原來的博客,一篇關於過期令牌處理沒有按」 t存在了。有新的文檔hewever可用於獲取詳細信息。 https://developers.facebook.com/docs/facebook-login/access-tokens/#extending

+1

您的所有鏈接都會給出「未找到網頁」,請更新鏈接 – 2014-11-05 07:47:13