我尝试了一个示例代码发布到Facebook页面。但它发布为我自己。我已经包含Page_access_token。PHP cURL:发布到Facebook页面为页面
授予的权限是'manage_pages'和'publish_action'。 这里是我的代码:
<?php
$page_id='xxxx';
$page_access_token='cccc';
$url="https://graph.facebook.com/{$page_id}/feed?message=Hello&access_token=".$page_access_token;
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_REFERER, '');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$value = json_decode(curl_exec($ch));
$var_dump($value);
?>
我在哪里出错了?我如何解决它? 我希望它作为页面发布。由于
编辑: 我与/ $ PAGE_ID新的代码字段=的access_token:
<?php
$page_id='xxx';
$message='helloworld';
$url="https://graph.facebook.com/v2.3/{$page_id}?fields=access_token";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_REFERER, '');
curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $message);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
$json = json_decode(curl_exec($curl));
var_dump($json);
?>
这将返回一个错误:
object(stdClass)#1 (1) {
["error"]=>
object(stdClass)#2 (3) {
["message"]=>
string(64) "(#210) A page access token is required to request this resource."
["type"]=>
string(14) "OAuthException"
["code"]=>
int(210)
}
}
我要去哪里错了?
我是否需要从图形API浏览器创建page_access_token?或者上面的url足够了?我该如何使用User_access_token来获取page_access_token?
你会得到什么回报? – 2015-04-06 06:18:21
它返回一个ID,这样的事情 stdClass的对象 ( [ID] => 1387602394895539_1390602811262164 ) 消息被发布到网页,但我自己没有 – SunShine 2015-04-06 06:32:24