سؤال

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. thrown in

any help in this regard.

هل كانت مفيدة؟

المحلول

You can use the FacebookApiException Class to catch the exceptions.

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; and you can check the object $sfqlResult->error;

if(!isset($sfqlResult['error']))
{
    // no error
}
else
{
    echo "Facebook error: ".$sfqlResult['error']->message;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top