2

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:

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:

<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?

twan
  • 2,450
  • 10
  • 32
  • 92

1 Answers1

2

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.

andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • Alright, makes sense, where can I add more permissions? When creating the page access token I only had the option to allow or deny, not any specific permissions. edit: nevermind, I see there is a button for it in the dropdownlist under my appname. – twan Aug 10 '16 at 11:18
  • you got manage_pages too, when generating a user token. just select publish_pages in addition. – andyrandy Aug 10 '16 at 11:31
  • yeah, there is even a seperate function to authorize publish_pages – andyrandy Aug 10 '16 at 11:32