使用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发布对特定提要的回复。有人能帮我解决这个问题吗?我还没有尝试过这个方法,但你应该尝试以下方法:
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' });