我知道,即使从Facebook获得的offline_access令牌也可能无效(例如,如果用户更改了密码)。在这种情况下,我需要捕获抛出的异常,并提供我的网站用户再次授权。Facebook OAuthException当offline_access令牌无效
那么这种情况下抛出的确切错误代码/消息是什么?我知道这是一个OAuthException
,但无法获得代码。不能只使用该类型,因为还有很多其他OAuthException
-s。
我的计划是:改变base_facebook.php
和添加的情况下手柄-ING代码在这里:
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;
}
对不起,但这不是我的问题的答案。当然,我打算在try-catch块中包装每个API调用!问题是捕获那些认证问题的确切例外是什么...... – ArVan 2012-05-28 21:26:52