[英]Facebook OAuthException when offline_access token is invalid
I know that even the offline_access token got from Facebook can be invalid (in case the user changed password for example). 我知道即使从Facebook获得的offline_access令牌也可能无效(例如,如果用户更改了密码)。 In that case I need to catch the thrown exception and offer the user of my site to authorize again. 在这种情况下,我需要捕获引发的异常并向我的网站用户提供再次授权。
So what is the exact error code/message thrown in this case? 那么在这种情况下抛出的确切错误代码/消息是什么? I know it's an OAuthException
, but wasn't able to get the code. 我知道这是OAuthException
,但无法获取代码。 Can't use just the type, as there are many other OAuthException
-s. 不能仅使用类型,因为还有许多其他OAuthException
-s。
My plan is: change the base_facebook.php
and add the case handle-ing code here: 我的计划是:更改base_facebook.php
并在base_facebook.php
添加案例处理代码:
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
/*
* Need to add an appropriate case here.
*/
case 'invalid_token':
$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;
}
Instead of changing the SDK, write a wrapper over it like 无需更改SDK,而是像上面那样编写包装器
try{
$facebook->api("/me/feed", .... );
}
catch($e){
//Error Handling
}
In case anyone needs it, I found the answer somehow. 万一有人需要,我以某种方式找到了答案。 The Exception for those kind of OAuthException is 190
. 这种OAuthException的Exception是190
。 Can be got from thrown exception like this: 可以从这样抛出的异常中获取:
$e->getCode(); $ e-> getCode();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.