0

我需要从 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 条记录。但只发布第一行。请为此提供解决方案

4

1 回答 1

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;

    } 
于 2012-08-12T10:01:17.983 回答