【问题标题】:facebook, post comment via php curlfacebook,通过 php curl 发表评论
【发布时间】:2011-11-09 01:49:53
【问题描述】:

从这里的一个教程:

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,所以post 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);

?>

【问题讨论】:

    标签: facebook curl


    【解决方案1】:
    curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
    

    应该是

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

    因为你不能发布数组

    【讨论】:

    • 你是对的,应该放一个完整的更长的access_token。我很疑惑,当我在朋友墙发帖时,只需要短的access_token,而评论需要更长的access_token。
    猜你喜欢
    • 2014-01-23
    • 1970-01-01
    • 1970-01-01
    • 2015-09-13
    • 2013-04-09
    • 1970-01-01
    • 2011-08-11
    • 2012-03-11
    • 2012-10-11
    相关资源
    最近更新 更多