Posting to a facebook page from a website using curl
<p>I am trying to build a script which posts data to a facebook page when a button is submitted.</p>

<p>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:</p>

<pre><code> {
      "error": {
        "message": "(#200) The user hasn't authorized the application to perform this action",
        "type": "OAuthException",
        "code": 200,
        "fbtrace_id": "BYNmxVAlESA"
      }
    }
</code></pre>

<p>I tried something like:</p>

<p>1745650152362669/feed?message=message&amp;access_token=myaccesstoken</p>

<p>and</p>

<p>1745650152362669/feed?fields=message=message&amp;access_token=myaccesstoken</p>

<p>both as <code>POST</code> ofcourse.</p>

<p>While I did give permissions to my app.</p>

<p>Like you can see here:</p>

<p><a href="https://i.stack.imgur.com/eLHs9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eLHs9.png" alt="enter image description here"></a></p>

<p>This token expires in an hour, so I press 'open in in access token pool'</p>

<p><a href="https://i.stack.imgur.com/GbNTe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GbNTe.png" alt="enter image description here"></a></p>

<p>And click extend access token:</p>

<p><a href="https://i.stack.imgur.com/jVRlh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jVRlh.png" alt="enter image description here"></a></p>

<p>I paste that token again in the graph api explorer but now the page is not selected anymore:
<a href="https://i.stack.imgur.com/qyag0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qyag0.png" alt="enter image description here"></a></p>

<p>Is that the way it's supposed to be?</p>

<p>I have the following code which should execute the post on submit:</p>

<pre><code>&lt;form&gt;
    &lt;input type="submit" name="submit"&gt;
&lt;/form&gt;
&lt;?

if(isset($_POST['submit'])){
    $token = 'mypageaccestoken';

    $attachment =  array(
    'access_token' =&gt; $token,
    'message' =&gt; $contentcr[0]['introtext'],
    'name' =&gt; $contentcr[0]['title'],
    'link' =&gt; $contentcr[0]['alias'].'html',
    'actions' =&gt; json_encode(array('name' =&gt; $action_name,'link' =&gt; $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);
}
</code></pre>

<p>The above code doesn't post anything to my page at the moment, can someone explain what I am missing?</p>