title: Facebook OAuth Fatal error: Uncaught OAuthException: An active access token
body: <p>I am getting this error when i try to use Facebook Connect.</p>
  
  <pre><code>Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /home/bakasura/public_html/ginger/app/vendors/facebook/facebook.php on line 543
  </code></pre>
  
  <p>Facebook Action</p>
  
  <pre><code>function facebook($authorize = null) {
      App::import('Vendor', 'facebook');
  
  $facebook = new Facebook(array(
                          'appId'=&gt; $this-&gt;__fbAppId,
                          'secret'=&gt; $this-&gt;__fbSecret,
                          'cookie'=&gt;true
                          ));
  
  $session = $facebook-&gt;getSession();
  
  if(!empty($session) &amp;&amp; ($authorize == null)){
      $login_url = $facebook-&gt;getLoginUrl(array(
                              'next' =&gt; Router::url(array('action' =&gt; 'facebook', 'authorize'), true),
                              'cancel_url' =&gt; Router::url(array('action' =&gt; 'login'), true),
                              'req_perms' =&gt; 'email,publish_stream',
                   ));
  
      header("Location:".$login_url);
  }
  
  $userInfo = $facebook-&gt;api('/me');
  
  if(!$userInfo){
      $this-&gt;Session-&gt;setFlash('Facebook login failed');
      $this-&gt;redirect(array('action' =&gt; 'login'));
  }
  
  
  $user = array(
      'User' =&gt; array(
          'first_name'       =&gt; $userInfo['first_name'],
          'last_name'        =&gt; $userInfo['last_name'],
          'username'        =&gt; $userInfo['username'],
          'email'           =&gt; $userInfo['email'],
          'user_group_id'   =&gt; 1,
          'status' =&gt; 'active'
      ),
      'Oauth' =&gt; array(
          'provider'        =&gt; 'facebook',
          'provider_uid'    =&gt; $userInfo['id']
      )
  );
  
  $this-&gt;oauthLogin($user);        
  }
  </code></pre>