如果在Facebook发布流脚本中发现致命错误,则继续循环

时间:2013-01-30 07:22:23

标签: php facebook loops fatal-error continue

我有以下PHP代码:

require 'facebook.php';
$facebook = new Facebook(array(
  'appId'  => 'XXXX',
  'secret' => 'XXXX',
));
$ids = array('1234','5678','1348','1476');
foreach ($ids as $id) {
    $USER_ID = $id; 
    $args = array( 
        'message'       =>  'Hello from XXXXX',
        'link'          =>  'http://www.xxxxx.com/',
        'caption'       =>  'Visit XXXXXXX.com for Facebook API Integration.',
        'picture'   =>  'http://www.xxxxxxx.com/busman.png'
    );
$post_id = $facebook->api("/$USER_ID/feed", "post", $args);
} 

它运行良好,偶尔有些用户可以卸载或撤消对facebook应用程序的访问以代表他/她发布,如果该用户标识在循环中,则整个过程停止在那里和下一个用户不感动。

即使遇到这个致命错误,我还能做些什么来继续循环:

  

致命错误:未捕获OAuthException:(#200)用户尚未授权应用程序在第1254行的/home/xxxxx/public_html/xxxxx/base_facebook.php中执行此操作<

BTW我正在使用PHP SDK for Facebook。提前谢谢。

1 个答案:

答案 0 :(得分:0)

尝试捕获异常。类似的东西:

try {

    $post_id = $facebook->api("/$USER_ID/feed", "post", $args);

} catch (FacebookApiException $e) {

    // Do something with the error if you want.
    // For example, remove it from your list so that your
    // script doesn't try to use this ID again.

} catch (Exception $e) {

    // Any other exception
}

更多信息: