title: facebook API how is onlogin called
body: <p>Can any one tell me how exactly the FB API works.
  It looks to be a basic question but I am really confused.</p>
  
  <p>Question:
  I have onlogin(). When I click the login button, I am expecting it to call this function.
  But in the code I pasted: I see that alert-test is printed first  and than the FB.api is called.</p>
  
  <p>So, it looks like onlogin is called first, then the FB API ...is there a way I can call this function only once.</p>
  
  <pre><code>&lt;body&gt;
          &lt;div id="fb-root"&gt;&lt;/div&gt;
  &lt;script&gt;
  
        window.fbAsyncInit = function() {
            FB.init({appId: 'XXX', status: true, cookie: true, xfbml: true});
  
        };
        (function() {
          var e = document.createElement('script'); e.async = true;
          e.src = document.location.protocol +
            '//connect.facebook.net/en_US/all.js';
          document.getElementById('fb-root').appendChild(e);
        }());
  
      function checkFacebookLogin() {
      FB.api('/me', function(response) {
          alert("Name: "+ response.name + "\nFirst name: "+ response.first_name + "ID: "+response.id);
      });
  
      alert('test');
  
      }
  
      &lt;/script&gt;
  
  
   &lt;p id="fb_login_button_1"&gt;&lt;fb:login-button  onlogin="checkFacebookLogin();"  size="medium" scope="user_about_me"&gt;Sign in using Facebook&lt;/fb:login-button&gt;&lt;/p&gt;
  
  
  &lt;/body&gt;v
  </code></pre>
  
  <p>My main issue is the function should be called only once....but it is getting called twice.</p>