验证访问令牌时出错 [英] Error Validating Access Token

查看:303
本文介绍了验证访问令牌时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶尔会收到此错误:


致命错误:未捕获异常:190:验证访问令牌时出错:这可能是因为用户注销或可能是由于系统错误。扔在..base_facebook.php行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);
开关($ e-> getType()){
// OAuth 2.0 Draft 00 style
case'OAuthException':
// OAuth 2.0 Draft 10 style
case'invalid_token':
// REST服务器错误只是例外
case'异常':
$ message = $ e-> getMessage();
如果(($ message,'验证访问令牌的错误')!== false)||
(struts($ message,'Invalid OAuth access token')!== false)){
$ this-> setAccessToken(null);
$ this-> user = 0;
$ this-> clearAllPersistentData();
}
}

throw $ e;

}



谢谢

解决方案

操作方法:处理过期的访问令牌 (链接已损坏)开发者博客文章


由于各种原因,用户的访问令牌可能无效。在大多数情况下,如果超过 expires 字段指定的时间(默认访问令牌的生命周期为2小时),它们可能会过期。许多开发人员没有意识到的是,如果用户更改密码,注销或通过App Dashboard取消授权,访问令牌也可能过期。您的应用程序处理这种情况非常重要。如果您的访问令牌过期,您需要重新获取有效的访问令牌。


在我们可以使用 offline_access 获取不过期的令牌的权限(除非用户与应用程序连接),此权限现在已被弃用,请参阅离线访问权限的弃用,以了解如何获得 access_token 更长的到期时间。 / p>

更新:

截至2012年8月Facebook PHP-SDK access_token (参见如何延长访问令牌的有效性,因为offline_access弃用重新细节)



更新2:
请注意,Facebook上关于过期令牌处理的原始博客文章不再存在。有新的文件,可以用来获取细节。
https://developers.facebook.com/docs/ facebook-login / access-tokens /#extensions


I get this error occasionally:

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

The issue is that I get it at random times, without any warning. I can go weeks without seeing it, then all of a sudden it will come up. The solution? You can wait it out. It throws this error for about 15 minutes then you can refresh and it will allow you to continue with what you were doing.

My question is, is this an issue on my end? Or is this a Facebook issue? This is a Facebook connect page if that helps. I did research and found out it could be caused from the FQL query. But then wouldn't it be consistent at least? It seems like it is completely random. Here is my FQL query anyway just in case.

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

Here are lines 1052-1071 of Base_Facebook,

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;

}

Thank you

解决方案

As written in How-To: Handle expired access tokens (link is broken) developers blog post

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.

Before we could use offline_access permission to get token that not expire (unless user is connected with application), this permission is now deprecated, see Deprecation of Offline Access Permission to see how you can get access_token with longer expiration time.

Update:
As of Aug 2012 Facebook PHP-SDK have added simple way of extending access_token (see How to extend access token validity since offline_access deprecation for more details)

Update 2: Note that original blog-post from Facebook about expired tokens handling doesn't exists anymore. There is new documentation hewever that may be used to get the details. https://developers.facebook.com/docs/facebook-login/access-tokens/#extending

这篇关于验证访问令牌时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆