忽略facebook错误并继续脚本

时间:2014-12-07 19:30:25

标签: php facebook facebook-php-sdk

有时我的脚本会出现这样的错误: (#803) Some of the aliases you requested do not exist

如何让我的脚本忽略此错误并继续获取数据?

CODE:

public function getClub($id) 
{
    $session = $this->fbStart();
    $GET = '?fields=about,category,company_overview,cover,founded,likes,link,location,name,phone,username,website';
    return (new FacebookRequest($session, 'GET', '/'.$id.$GET.''))->execute()->getGraphObject(GraphUser::className())->asArray();
}

foreach ($ids as $id) {
    $club = $model->getClub($id);
    $model->saveClub($club);
}

1 个答案:

答案 0 :(得分:1)

根据您更新的代码,您可能只需要在其中添加if / else。

编辑:您正在使用方法链版本,将其分解为非链接版本。然后,您可以使用if / else处理异常并返回错误。这来自FB SDK文档:

try {
      $response = (new FacebookRequest($session, 'GET', '/me'))->execute();
      $object = $response->getGraphObject();
      // Here is likely where you will get the error back, though I am guessing,
      // I have never used their SDK...
      echo $object->getProperty('name');
} catch (FacebookRequestException $ex) {
      // Or here is where the message will come back
      echo $ex->getMessage();
} catch (\Exception $ex) {
      echo $ex->getMessage();
}

以下是链接:https://developers.facebook.com/docs/php/FacebookRequest/4.0.0