我嘗試了一個示例代碼發佈到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