facebook,通过php curl发表评论

时间:2011-09-02 10:26:32

标签: facebook curl

从这里的一个教程:

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

我试图在一篇帖子后发表评论,但是回复:

[type] => OAuthException [message] => (#200) The user hasn't authorized the application to perform this action

这不是我的应用程序帐号墙的帖子ID,我试过我的朋友墙,他已经允许我的应用程序,我可以发布帖子到他的墙上,但在评论中失败,我得到了帖子ID https://graph.facebook.com/<his fid>/feed?access_token=140XXXXXXXXXXX,因此帖子ID没有问题。

我错过了哪些步骤?

$fbId = '100001102789652_233997699980321';
$accessToken = '140XXXXXXXXXXXX';
$url = "https://graph.facebook.com/{$fbId}/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);

&GT;

1 个答案:

答案 0 :(得分:0)

curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);

应该是

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($attachment));

因为你不能发布数组

相关问题