【发布时间】:2012-02-23 16:26:29
【问题描述】:
我正在尝试使用 curl 将帖子发布到我的 facebook 页面墙上,但我不断收到以下错误
The user hasn't authorized the application to perform this action
如何使用 curl 生成正确的访问令牌?如果你去这个网址http://developers.facebook.com/tools/explorer/
然后我可以输入以下https://graph.facebook.com/337588736279406/feed,这将显示我的墙提要,然后我可以将其更改为发布并为消息内容添加一个字段,如果我运行它,我会得到以下响应。
{
"error": {
"message": "(#200) The user hasn't authorised the application to perform this action",
"type": "OAuthException",
"code": 200
}
}
我需要做什么才能授权我成为用户?
有人可以帮我解决这个问题吗?
<?php
function postify($arr) {
$fields_string = '';
foreach ($arr as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
return rtrim($fields_string, '&');
}
$appid = 'app id';
$redirect_url = 'http://stickynote.users36.interdns.co.uk';
$app_secret = 'app secret';
$page_id = '337588736279406';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id='.$appid.'&redirect_uri='.$redirect_url.'&client_secret='.$app_secret.'&perms=publish_stream');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$output = explode("=", $output);
curl_close($ch);
$postdata = array(
'message' => 'this is a test message',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/'.$page_id.'/feed?access_token='.$output[1].'');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, postify($postdata));
$check = curl_exec($ch);
print_r($check);
?>
【问题讨论】:
标签: php facebook facebook-wall