我想获得我的 api 异常,但我不明白该怎么做。这是我的代码
public function facebook($link){
if(!$link || !trim($link) != ""){
return false;
}
$config = array(
'appId'=>$this->keys['facebook']['id'],
'secret'=>$this->keys['facebook']['secret'],
'fileUpload'=>false
);
$facebook = new Facebook($config);
$start = strrpos($link, '/', -1);
$end = strripos($link, '?', -1);
$end = ($end)?$end:strlen($link);
$pageId = ($end == strlen($link))?substr($link, $start + 1):substr($link, $start + 1, $end - strlen($link));
try {
$pagefeed = $facebook->api("/" . $pageId . "/feed");
}
catch (FacebookApiException $e){
return false;
}
//set datetime
foreach ($pagefeed['data'] as $key => $post){
$pagefeed['data'][$key]['datetime'] = new \DateTime($post['created_time']);
}
return $pagefeed;
}
所以我想在异常的情况下返回 false 。
我举个例子:
BaseFacebook ->throwAPIException (array('error' => array('message' => '(#803) Some of the aliases you requested do not exist: lkdsgfkqdjgflkdshbf', 'type' => 'OAuthException', 'code' => '803')))
谢谢你的帮助