2011-04-22 83 views
3

在Facebook上評論的回覆,我知道如何發佈在朋友的牆上的飼料。例如:後使用捲曲PHP /圖形API

$url = 'https://graph.facebook.com/' . $fbId . '/feed'; 

$attachment = array(
     'access_token' => $accessToken, 
     'message'  => $msg, 
     'name'   => $name, 
     'link'   => $link, 
     'description' => $desc, 
     'picture'  => $logo, 
); 

// set the target url 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
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_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$go = curl_exec($ch); 
curl_close ($ch); 

$go = explode(":", $go); 
$go = str_ireplace('"', '', $go[1]); 
$go = str_ireplace('}', '', $go); 
return $go; 

但我想知道,如何發佈使用PHP捲曲或Facebook圖形API的特殊飼料的答覆。有人能幫我解決這個問題嗎?

回答

2

你有沒有嘗試過這樣的:

https://graph.facebook.com/" . $go . "/comment

我想,如果你可以發佈與飼料/feed,那麼你就可以發佈評論與/comment網址。

謝謝。

0

我沒有試過,但你應該試試下面的方法:

  1. 讓您剛剛發佈的帖子的ID。檢查是否有任何值圖api返回。 如果沒有,你可以從「ID」字段的ID在「https://graph.facebook.com/".$fbId."/feed」。

  2. 使用FB.api( '/ [POST_ID] /評論', '後',{ '消息': '註釋交'}); 確保您有publish_stream特權ofcourse。

+0

你是對的,這可能會工作。但它使用Facebook PHP API。但我不能使用Facebook API。我想要使​​用Graph API/cURL的解決方案。而且,僅供參考,我會在'$ go'變量中發佈Feed的ID。 – 2011-04-23 04:10:43

4

好吧,首先,這是提取ID更好的辦法:

$go = json_decode($go, TRUE); 
if(isset($go['id'])) { 
// We successfully posted on FB 
} 

所以,你會使用類似:

$url = 'https://graph.facebook.com/' . $fbId . '/feed'; 

$attachment = array(
     'access_token' => $accessToken, 
     'message'  => "Hi", 
); 

// set the target url 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
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_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$go = curl_exec($ch); 
curl_close ($ch); 

$go = json_decode($go, TRUE); 
if(isset($go['id'])) { 
    $url = "https://graph.facebook.com/{$go['id']}/comments"; 

    $attachment = array(
      'access_token' => $accessToken, 
      'message'  => "Hi comment", 
    ); 

    // set the target url 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    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_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $comment = curl_exec($ch); 
    curl_close ($ch); 
    $comment = json_decode($comment, TRUE); 
    print_r($comment); 
} 

enter image description here

+0

此解決方案先前由@Ketan提出。我已經實現了它。謝謝@發明 – 2011-04-23 18:57:29

3

使用

FB.api('/[POST_ID]/comments', 'post', { 'message' : 'comment post' }); 

確保您擁有publish_stream權限,當然。