【问题标题】:Post a reply on a comment in Facebook using cURL PHP / Graph API使用 cURL PHP / Graph API 在 Facebook 中回复评论
【发布时间】:2011-08-11 03:19:23
【问题描述】:

我知道如何在朋友的墙上发布信息。例如:

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

但我想知道,如何使用 cURL PHP 或 Facebook Graph API 发布对特定提要的回复。谁能帮我解决这个问题?

【问题讨论】:

    标签: php facebook curl facebook-graph-api feed


    【解决方案1】:

    好的,首先,这是提取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);
    }
    

    【讨论】:

    • @Ketan 以前曾建议过此解决方案。我已经实现了它。谢谢@ifaour
    【解决方案2】:

    使用

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

    确保您当然拥有 publish_stream 权限。

    【讨论】:

      【解决方案3】:

      你试过了吗:

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

      我认为,如果您可以使用/feed 发布提要,那么您可以使用/comment url 发表评论。

      谢谢。

      【讨论】:

        【解决方案4】:

        这个我没试过,但是你应该试试下面的方法:

        1. 获取您刚刚发布的帖子的 ID。检查是否有任何值 graph api 返回。 如果没有,您可以从“https://graph.facebook.com/”.$fbId.“/feed”中的“id”字段中获取 id。

        2. 使用 FB.api('/[POST_ID]/cmets', 'post', { 'message' : 'comment post' }); 当然,请确保您拥有 publish_stream 权限。

        【讨论】:

        • 你是对的,这可能会奏效。但它使用 Facebook PHP API。但我不能使用 Facebook API。我想要使​​用 Graph API / cURL 的解决方案。仅供参考,我将在 $go 变量中发布提要的 ID。
        猜你喜欢
        • 2018-07-13
        • 1970-01-01
        • 2018-11-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-10
        相关资源
        最近更新 更多