2012-07-24 87 views
0

我想发布状态消息给多个FB用户,但不是他们在我的网站上。我为每个发布的用户发布了publish_stream perms和60天访问令牌,但我无法弄清楚如何正确批量发布。批量墙贴到多个Facebook帐户使用PHP

这是放入访问令牌的正确方法吗?

$body = array(
      'message' => $message, 
      'link' => $link, 
      'picture' => $picture, 
      'name' => $name, 
      'description'=> $description 
      ); 
    $batchPost=array(); 
    $i=1;  
    foreach ($user_fb_id_array as $fb_id) { 
     $batchPost[] = array(
      'method' => 'POST', 
      'relative_url' => "/" . $fb_id['user_fb_id'] . "/feed?access_token=" . $fb_id['user_fb_auth_code'], // Will this work??? 
      'body' => http_build_query($body)); 
     if($i++ == 50) { 
      try { 
       $multiPostResponse = $this->facebook->api('?batch='.urlencode(json_encode($batchPost)), 'POST'); 
      } catch(FacebookApiException $e) { 
       error_log($e); 
       echo("Batch Post Failed"); 
      } 
      unset($batchPost); 
      $i=1; 
     } 
    } 

    if(isset($batchPost) && count($batchPost) > 0) { 
     try{ 
      $multiPostResponse = $this->facebook->api('?batch='.urlencode(json_encode($batchPost)), 'POST'); 
     } catch(FacebookApiException $e){ 
      error_log($e); 
      echo("Batch Post Failed"); 
     } 
    } 

要在信用到期时给予抵免,此代码已从25labs.com原始代码修改。

回答

0

访问令牌应该为与'method'和'relative_url'相同级别的每个调用定义,但是您的方法也可能工作。

实际上您是否收到错误消息,或者您只是问如何实现?

+0

这是我从文档的理解,是的 – Igy 2012-07-25 09:19:45