title: Facebook authentication in function - getUser() returns 0
body: <p>I'm trying to make a function in my controller to post an album to Facebook.  Every time the function is accessed, I'm redirected to REDIRECT_URI, as if the $userid=0, even if I just correctly logged into Facebook.  Is this because after logging in, it restarts the function and creates a new Facebook session, wiping out the user I just got?</p>
  
  <p>Thanks for any help you can provide.</p>
  
  <pre><code> function share($id){
              if (!$id) { $this-&gt;Session-&gt;setFlash(__('Invalid id for Album', true)); 
              $this-&gt;redirect(array('action'=&gt;'index')); }  
              $photos = $this-&gt;Album-&gt;find('all', array('conditions' =&gt; array('Album.id' =&gt; $id))); 
  
  
              $facebook = new Facebook(array('appId'=&gt;'valid aphid', 'secret'=&gt;'valid secret')); 
              $facebook-&gt;setFileUploadSupport(true);
              $userid = $facebook-&gt;getUser(); 
  
              if($userid) {               
                  try {
                        $user_profile = $facebook-&gt;api('/me'); // Gets User's information based on permissions the user has granted to your application.
  
                  } 
                  catch(FacebookApiException $e){
                      error_log($e);
                      // Print results if you want to debug.
                      $userid = null;
                  }
  
              } else {
  
                  $login_url = $facebook-&gt;getLoginUrl($params = array('redirect_uri' =&gt; REDIRECT_URI,'scope' =&gt; PERMISSIONS_REQUIRED));
                  echo ("&lt;script&gt; top.location.href='".$login_url."'&lt;/script&gt;");
              }
  
              //Create album
              $results = $facebook-&gt;api('me/albums', 'post', $photos[0]['Album']['name']);//-&gt;photos_createAlbum($albumname, '', '', 'everyone', $this-&gt;_userid); 
  
          }
  </code></pre>