Posting to a facebook page from a website using curl

女生的网名这么多〃 提交于 2020-02-01 08:10:11

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/38871639/posting-to-a-facebook-page-from-a-website-using-curl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!