使用curl进行多个facebook发布

时间:2012-08-12 09:32:17

标签: php curl

我需要从mysql数据库发布多条消息到facebook墙。首先我从mysql中获取数据并将其放入while循环

while($row=mysql_fetch_array($result))
      {

$des=$row[1];
$purpose=$row[3];
$price_sale=$row[4];
$price_rent=$row[5];
$img="example.com/images".mysql_result($result,0,2);


  $attachment =  array(
    'access_token' => "$token",
    'message' => $des,
    'picture' => $img,
    'link' => "example.com"
    );

$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/xxxxxxxxxxx/feed');

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output 
$result = curl_exec($ch);
curl_close ($ch);


echo $result;

} 

$ result包含3条记录。但只发布第一行。 Plz为此提供了解决方案

1 个答案:

答案 0 :(得分:1)

尝试更改接受curl输出的变量的名称。您正在使用上面的相同变量。

   while($row=mysql_fetch_array($result))
          {

    $des=$row[1];
    $purpose=$row[3];
    $price_sale=$row[4];
    $price_rent=$row[5];
    $img="example.com/images".mysql_result($result,0,2);


      $attachment =  array(
        'access_token' => "$token",
        'message' => $des,
        'picture' => $img,
        'link' => "example.com"
        );

    $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/xxxxxxxxxxx/feed');

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output 
    $curlresult = curl_exec($ch);
    curl_close ($ch);


    echo $curlresult;

    }