title: Facebook API - Run javascript after user has logged in
body: <p>at the minute I have this:</p>
  
  <pre><code>&lt;div id="fb-root"&gt;&lt;/div&gt;
  &lt;script src="http://connect.facebook.net/en_US/all.js"&gt;&lt;/script&gt;    
  &lt;script&gt;
    window.fbAsyncInit = function() {
      FB.init({ appId:'188492754501683', cookie:true, status:true, xfbml:true }); 
    };
  &lt;/script&gt; 
  &lt;fb:login-button perms="email"&gt;
    login with Facebook
  &lt;/fb:login-button&gt;    
  </code></pre>
  
  <p>I want to run some code to pull the email aswell, say this:</p>
  
  <pre><code>FB.api('/me', function(res) { if (res != null) { alert(res.email); } } );
  </code></pre>
  
  <p>When I added this under the call to FB.init(), it was run as soon as the window loaded, which is understandable but not what I wanted.</p>
  
  <p>I want the code to run AFTER the user has clicked the Login With Facebook button, and then successfully logged in, etc.</p>
  
  <p>Can anyone point me in the right direction, I've searched google but can't seem to find anything :/</p>
  
  <p>Thanks in advance, Tom.</p>