I tried a sample code to post to Facebook page. But it is posting as myself. I have included Page_access_token.
permission granted is 'manage_pages' and 'publish_action'. Here is my code :
<?php
$page_id='xxxx';
$page_access_token='cccc';
$url="http://ift.tt/1xUZkjw".$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);
?>
Where am I going wrong ? How do I solve it ? I want it to be posted as page. Thanks
My new code with /$PAGE_ID?fields=access_token:
<?php
$page_id='xxx';
$message='helloworld';
$url="http://ift.tt/1GGjE9K";
$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);
?>
This returns an error :
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)
}
}
Where am I going wrong ?
Do I need to create the page_access_token from graph API explorer? or the above url is enough? How I am supposed to use User_access_token to get page_access_token ?
Aucun commentaire:
Enregistrer un commentaire