title: "An active access token must be used" (Dec 2012) && The proper way to set up Facebooks PHP-SDK for Ajax calls to get the user-id
body: <p>This is giving me quite some headache. I have an page-tab-application, where DB-interaction uses the facebook-user-id to assign and save data and also to check user permissions. Until a weak ago everything was working fine, but now with the upcoming december-changes this setup doesnt work anymore:</p>
  
  <p><strong>config.php:</strong></p>
  
  <pre><code>$facebook = new Facebook( array(
  'appId' =&gt; $app_id,
  'secret' =&gt; $app_secret,
  'cookie' =&gt; true
  )); 
  </code></pre>
  
  <p><strong>index.php:</strong>
  includes config.php and gets the signed request (not important for the question</p>
  
  <p><strong>javascript.js:</strong>
  calls the read-user-status.php and handles the data</p>
  
  <p><strong>read-user-status.php:</strong>
  gives json-response, includes config.php and calls the $facebook -> getUser()-function to get the uid</p>
  
  <p>Even when called from the index.php directly after page-load, I sometimes get the uid and sometimes I don't. Strangly enough I usually have to wait a little until I reload the page and then it works again. But this isn't always the case. This all is just very strange to me.</p>
  
  <p><strong>EDIT:</strong> Should have mentioned that this call:</p>
  
  <pre><code>$uid = $facebook -&gt; getUser();
  if ($uid) {
      try {
         // Proceed knowing you have a logged in user who's authenticated.
         $user_profile = $facebook -&gt; api('/me');
      } catch (FacebookApiException $e) {
         error_log($e);
         $uid = FALSE;
       echo "EXCEPTION $e";
     }
  }
  </code></pre>
  
  <p>gives out "EXCEPTION An active access token must be used to query information about the current user".</p>
  
  <p>I know there quite a lot of similar questions out there, but none of the answers were helpful to my particular (and probably to the new breaking changes relied) problem.</p>
  
  <p><strong>EDIT2:</strong> I now suppose that it is a sdk-bug (<a href="https://developers.facebook.com/bugs/238039849657148" rel="nofollow">https://developers.facebook.com/bugs/238039849657148</a> , thanks to CBroe). Any recommendations for a work-around are of course very welcome.</p>
  
  <p><strong>EDIT 3, TEMPORARY SOLUTION</strong>
  Everytime you make an ajax request, you post the token you get from the FB.getLoginStatus or FB.login and read it out in the php file and set it via $facebook -> setAccessToken. Not suitable in all circumstances (you definately need to use post), is slower and brings some security issues, but still works.</p>