[英]exception handling with PHP and facebook
I have the following code: 我有以下代码:
$fql = "SELECT first_name, last_name FROM user where uid=me()";
$sparam = array('method' => 'fql.query', 'query' => $fql, 'callback' => '', 'access_token' => $fbtoken);
try{
$sfqlResult = $facebook -> api($sparam);
}
catch(CurlException $e) {
echo 'There is issue with Token';
}
suppose if my access token is wrong I want to catch the exception, but its not catching the exception and showing traditional error 假设如果我的访问令牌是错误的,我想捕获异常,但是它没有捕获异常并显示传统错误
Fatal error: Uncaught Exception: 190: Invalid OAuth access token.
致命错误:未捕获的异常:190:无效的OAuth访问令牌。 thrown in
扔进去
any help in this regard. 在这方面有任何帮助。
You can use the FacebookApiException Class to catch the exceptions. 您可以使用FacebookApiException类来捕获异常。
Example- 例-
try {
$sfqlResult = $facebook -> api($sparam);
} catch(FacebookApiException $e) {
$e_type = $e->getType();
$result = $e->getResult();
error_log('Got an ' . $e_type . ' while posting');
error_log(json_encode($result));
}
But according to me, there's token related issue, the exception will not be thrown but the error result will be returned in $sfqlResult
; 但是据我说,存在与令牌相关的问题,不会引发异常,但是错误结果将在
$sfqlResult
返回; and you can check the object $sfqlResult->error;
您可以检查对象
$sfqlResult->error;
if(!isset($sfqlResult['error']))
{
// no error
}
else
{
echo "Facebook error: ".$sfqlResult['error']->message;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.