Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用cURL-PHP/Graph-API在Facebook上发布评论回复_Php_Facebook_Curl_Facebook Graph Api_Feed - Fatal编程技术网

使用cURL-PHP/Graph-API在Facebook上发布评论回复

使用cURL-PHP/Graph-API在Facebook上发布评论回复,php,facebook,curl,facebook-graph-api,feed,Php,Facebook,Curl,Facebook Graph Api,Feed,我知道如何在朋友的墙上发布提要。例如: $url = 'https://graph.facebook.com/' . $fbId . '/feed'; $attachment = array( 'access_token' => $accessToken, 'message' => $msg, 'name' => $name, 'link' => $lin

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

$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发布对特定提要的回复。有人能帮我解决这个问题吗?

我还没有尝试过这个方法,但你应该尝试以下方法:

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

  • 使用FB.api('/[POST_ID]/comments','POST',{'message':'commentpost'}); 当然,请确保您拥有“发布流”权限

  • 你试过这个吗:

    https://graph.facebook.com/“$go.”注释

    我想,如果你可以用
    /feed
    发布feed,那么你可以用
    /comment
    url发布评论


    谢谢。

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


    当然,请确保您拥有“发布流”权限。

    您是对的,这可能会起作用。但它使用Facebook PHP API。但我不能使用Facebook API。我想要使用GraphAPI/cURL的解决方案。仅供参考,我将在
    $go
    变量中发布提要的ID。此解决方案以前由@Ketan建议。我已经实现了它。谢谢@ifaour
    FB.api('/[POST_ID]/comments', 'post', { 'message' : 'comment post' });