twan twan - 7 months ago 31
PHP Question

Posting to a facebook page from a website using curl

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:




both as

While I did give permissions to my app.

Like you can see here:

enter image description here

This token expires in an hour, so I press 'open in in access token pool'

enter image description here

And click extend access token:

enter image description here

I paste that token again in the graph api explorer but now the page is not selected anymore:
enter image description here

Is that the way it's supposed to be?

I have the following code which should execute the post on submit:

<input type="submit" name="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,'');
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?


The user hasn't authorized the application to perform this action

That error means that you are missing the appropriate permission. You need publish_pages to post (as Page), not just manage_pages.