error-handling - 验证访问 token 时出错

标签 error-handling facebook

我偶尔会遇到这个错误:

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 的第 1052-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;

谢谢

最佳答案

中所写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 权限获取不会过期的 token (除非用户与应用程序连接)之前,此权限现已弃用,请参阅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 的关于过期 token 处理的原始博客文章不再存在。有新的文档可以用来获取详细信息。 https://developers.facebook.com/docs/facebook-login/access-tokens/#extending

关于error-handling - 验证访问 token 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9060336/

相关文章:

wpf - Task.Run中的全局错误处理可实时通知用户

authentication - 登录失败 : unknown user name or bad password

swift - 请求 iOS 应用程序 Facebook 应用程序事件的跟踪授权

php - 如何在 magento 网站上进行 facebook 登录集成?

iphone - Facebook iOS 整合

java - 如何使用Retroift2实现自定义错误处理

c++ - 如何解决在开发 C++ 中未定义的对 readimagefile 的引用错误

java - 在 Java 中解析 XML 文件并输出所有错误

facebook - 如何更改 Facebook 或其他平台上视频的播放速度

c# - Facebook SDK for .NET 登录按钮、注销代码