-1

我有以下 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 处于循环中,则整个过程将停止在那里并且下一个用户不会被触及.

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

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

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

4

1 回答 1

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
}

更多信息:

于 2013-01-30T07:43:22.490 回答