I am trying to build a script which posts data to a facebook page when a button is submitted.
I created a non expiring page access token but I'm stuck on how to build the url. Several tests in the graph api explorer keep giving me:
{
"error": {
"message": "(#200) The user hasn't authorized the application to perform this action",
"type": "OAuthException",
"code": 200,
"fbtrace_id": "BYNmxVAlESA"
}
}
I tried something like:
1745650152362669/feed?message=message&access_token=myaccesstoken
and
1745650152362669/feed?fields=message=message&access_token=myaccesstoken
both as POST
ofcourse.
While I did give permissions to my app.
Like you can see here:
This token expires in an hour, so I press 'open in in access token pool'
And click extend access token:
I paste that token again in the graph api explorer but now the page is not selected anymore:
Is that the way it's supposed to be?
I have the following code which should execute the post on submit:
<form>
<input type="submit" name="submit">
</form>
<?
if(isset($_POST['submit'])){
$token = 'mypageaccestoken';
$attachment = array(
'access_token' => $token,
'message' => $contentcr[0]['introtext'],
'name' => $contentcr[0]['title'],
'link' => $contentcr[0]['alias'].'html',
'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/1745650152362669/feed');
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_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close ($ch);
}
The above code doesn't post anything to my page at the moment, can someone explain what I am missing?