title: Facebook PHP SDK - OAuthException - OAuth2
body: <p>How are you supposed to deal with people who signed into Facebook a while ago. Come to your site you should them a continue link (because you detect that they are already logged into Facebook) and then on the page you direct them to you get this error.  </p>
  
  <p><code>Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /var/www/html/lib/base_facebook.php on line 1039
  </code>  </p>
  
  <p>I don't understand how you are supposed to prevent this? Does this have something to do with the signed info that you give back to Facebook to get an access_token? Seems like this signed info can expire (it has an issued_at date). What is the correct way to handle this in your website's flow?</p>
  
  <p>Are you expected to write code like this:</p>
  
  <pre><code>&lt;?php 
  $user = $facebook-&gt;getUser();
  try {
    // attempt to do a call just to see if you are going to have this issue
    $profile = $facebook-&gt;api('/me'); 
  } catch (Exception $e) {
    $user = false;
  }
  if ($user) { ?&gt;
    &lt;a href="start.php"&gt;Begin&lt;/a&gt;
  &lt;?php } else { ?&gt;
      &lt;fb:login-button scope="email" size="large"&gt;Connect&lt;/fb:login-button&gt;
  &lt;?php } ?&gt;
  </code></pre>
  
  <p>Instead of this:</p>
  
  <pre><code>&lt;?php 
  $user = $facebook-&gt;getUser();
  if ($user) { ?&gt;
    &lt;a href="start.php"&gt;Begin&lt;/a&gt;
  &lt;?php } else { ?&gt;
      &lt;fb:login-button scope="email" size="large"&gt;Connect&lt;/fb:login-button&gt;
  &lt;?php } ?&gt;
  </code></pre>
  
  <p>Getting the $user back from the Facebook SDK only seems to tell you there is a cookie. And not if that will actually work when you go to do the API calls.</p>
  
  <p><strong>UPDATE</strong>:
  So my only problem with this method is ... when the user does have a cookie on my site, but the API call fails - I show them the connect button. User clicks the connect button, it quickly appears and disappears. Because it wasn't a true 'auth.login' that just occured, the user will not get sent to my start.php page via JavaScript redirect. How do others handle this? I'm stumped. Please tell me if there are other flaws with how I'm attempting to do this.</p>