【问题标题】:Continue the loop if a Fatal Error is found in a Facebook publish stream script如果在 Facebook 发布流脚本中发现致命错误,则继续循环
【发布时间】:2013-01-30 07:22:22
【问题描述】:

我有以下 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 应用程序的访问权以代表他/她发布,如果该用户 ID 处于循环中,则整个过程将停止在那里,下一个用户没碰过。

即使出现此致命错误,我该怎么做才能继续循环:

Fatal error: Uncaught OAuthException: (#200) The user has not authorized the application to perform this action throw in in /home/xxxxx/public_html/xxxxx/base_facebook.php on line 1254

顺便说一句,我正在为 Facebook 使用 PHP SDK。提前致谢。

【问题讨论】:

标签: php facebook loops fatal-error continue


【解决方案1】:

尝试捕获异常。比如:

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
}

更多信息:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-11
    • 1970-01-01
    • 1970-01-01
    • 2014-10-16
    • 1970-01-01
    • 2022-06-18
    • 1970-01-01
    • 2020-10-14
    相关资源
    最近更新 更多