2011-04-22 82 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权限,当然。