Facebook: OAuthException: (#200) Must have a valid access_token to access this endpoint
<p>i am trying to fetch all the public events from facebook,</p>

<p>when i try to execute my php code from my server i get the error: <strong>Uncaught OAuthException: (#200) Must have a valid access_token to access this endpoint thrown in /....../sdk/src/base_facebook.php on line 1254</strong></p>

<p>while if i execute the same code on heroku... it works.... i want to execute the code on my server.... plz help.... my code is.. :</p>

<pre><code>    &lt;?php

require_once('utils.php');

require_once('sdk/src/facebook.php');

$facebook = new Facebook(array(
  'appId'  =&gt; '.........',
  'secret' =&gt; '..............',
  'sharedSession' =&gt; true,
  'trustForwarded' =&gt; true,
));

$events =idx($facebook-&gt;api('/search?q=trade&amp;type=event&amp;limit=5000&amp;access_token=ksdkslhosihgksjdhlshfshdfgskdjhsklfhsklfhskfjhsdlkhslhslh'), 'data', array());

$var=1;

foreach($events as $event)
{

    $id = idx($event, 'id');
    $name = idx($event, 'name');
    $owner = idx($event, 'owner');
    $start_time = idx($event, 'start_time');
    $end_time = idx($event, 'end_time');
    $location = idx($event, 'location');
    $description = idx($event, 'description');
     echo "S.No:".$var."&lt;br&gt;";
     echo "ID:".he($id)."&lt;br&gt;";
     echo "Name:".he($name)."&lt;br&gt;";
     echo "Owner:".he($owner)."&lt;br&gt;";
     echo "start_time:".he($start_time)."&lt;br&gt;";
     echo "end_time:".he($end_time)."&lt;br&gt;";
     echo "location:".he($location)."&lt;br&gt;";
     echo "description:".he($description)."&lt;br&gt;";
     $var=$var+1;
}   

?&gt;
</code></pre>

<p>the util.php file used is same as in heroku.....</p>

<p>util.php</p>

<pre><code>    &lt;?php

/**
 * @return the value at $index in $array or $default if $index is not set.
 */
function idx(array $array, $key, $default = null) {
  return array_key_exists($key, $array) ? $array[$key] : $default;
}

function he($str) {
  return htmlentities($str, ENT_QUOTES, "UTF-8");
}
</code></pre>
