Post a reply on a comment in Facebook using cURL PHP / Graph API

空扰寡人 提交于 2019-12-04 03:46:52

问题


I know how to post a feed on the friend's wall. eg:

$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;

But I want to know, how to post a reply to the particular feed using cURL PHP or Facebook Graph API. Can anybody help me out from this problem?


回答1:


Have you tried this:

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

I think, if you can post a feed with /feed, then you can post comment with /comment url.

Thank you.




回答2:


Okay, first of all, this is a better way of extracting the id:

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

So you would use something like:

$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);
}




回答3:


Use

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

Make sure you have the publish_stream privilege of course.




回答4:


I haven't tried this, but you should try the following method:

  1. get the id of the post you just posted. Check if there are any values graph api returns. if not, you can get the id from the "id" field in "https://graph.facebook.com/".$fbId."/feed".

  2. use FB.api('/[POST_ID]/comments', 'post', { 'message' : 'comment post' }); make sure you have the publish_stream privilege ofcourse.



来源:https://stackoverflow.com/questions/5758501/post-a-reply-on-a-comment-in-facebook-using-curl-php-graph-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!