php - 使用 cURL PHP/Graph API 在 Facebook 中发布对评论的回复

标签 php facebook curl facebook-graph-api feed

我知道如何在 friend 的墙上发布动态。例如:

$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 的更好方法:

$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

关于php - 使用 cURL PHP/Graph API 在 Facebook 中发布对评论的回复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5758501/

相关文章:

php - 获得准确的 Facebook 点赞数

php - 如何避免使用 PHP cURL 进行 URL 通配?

bash - 如何使用 curl 通过 bash 脚本将表情符号发送到 Telegram 机器人?

PHP运算符&&与 "and"的区别

php - 使用变量设置背景 URL - 我做错了什么?

java - 通过指定关键字提取url

javascript - Facebook Like Box 只显示一张脸

android - 无法在 Android Webview 中打开 Facebook 消息

php - 如何通过curl传递包含特殊字符的数据

php - 将此curl命令翻译为php curl