title: facebook login error FB.login() called before FB.init()
body: <p>i have a problem with loggin in into facebook i keep getting the error code: FB.login() called before FB.init(). i done various things but keep getting the error.
  here's the html code: </p>
  
  <pre><code> &lt;!-- Javascript
          =================================================== --&gt;
          &lt;script src="//connect.facebook.net/en_US/all.js"&gt;&lt;/script&gt;
          &lt;script src="js/facebook.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;div id="fb-root"&gt;&lt;/div&gt;
          &lt;script&gt;
              var email;
              var name;
              window.fbAsyncInit = function() 
              {
                  FB.init({
                      appId      : '509855929050339', // App ID
                      status     : true, // check login status
                      cookie     : true, // enable cookies to allow the server to access the session
                      xfbml      : true  // parse XFBML
                  });
  
                  FB.Event.subscribe('auth.login', function () {
                      window.location = "http://webs.hogent.be/~096506gd/home.html";
                  });
                  FB.getLoginStatus(function(response) {
                      if (response.status === 'connected') {
                          // the user is logged in and has authenticated your
                          // app, and response.authResponse supplies
                          // the user's ID, a valid access token, a signed
                          // request, and the time the access token 
                          // and signed request each expire
                          var uid = response.authResponse.userID;
                          var accessToken = response.authResponse.accessToken;
                          window.location = "http://webs.hogent.be/~096506gd/home.html";
                      } else if (response.status === 'not_authorized') {
                          // the user is logged in to Facebook, 
                          // but has not authenticated your app
                      } else {
                          // the user isn't logged in to Facebook.
                      }
                  });
  
              };
  
              // Load the SDK asynchronously
              (function(d){
                  var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
                  if (d.getElementById(id)) {return;}
                  js = d.createElement('script'); js.id = id; js.async = true;
                  js.src = "//connect.facebook.net/en_US/all.js";
                  ref.parentNode.insertBefore(js, ref);
              }(document));
          &lt;/script&gt;
          &lt;div class="container"&gt;
              &lt;img class="offset-by-three ten columns margin-top25" src="images/logo.png"&gt;
              &lt;div class="offset-by-five"&gt;
                  &lt;a class="six columns full-width button margin-top175" href="home.html"&gt;
                      Aanmelden
                  &lt;/a&gt;
                  &lt;a class="six columns full-width button margin-top175" onclick="loginUser()"&gt;
                      Aanmelden met facebook
                  &lt;/a&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and this is the javascript file:</p>
  
  <pre><code>function loginUser(){
      FB.login(function(response) {
  
          if (response.authResponse) {
              console.log('Welcome!  Fetching your information.... ');
              //console.log(response); // dump complete info
              access_token = response.authResponse.accessToken; //get access token
              user_id = response.authResponse.userID; //get FB UID
  
              FB.api('/me', function(response) {
                  alert ("email: "+response.email); //get user email
                  alert ("naam : "+respone.name);
  
            // you can store this data into your database             
              });
  
          } else {
              //user hit cancel button
              console.log('User cancelled login or did not fully authorize.');
  
          }
      }, {
          scope: 'publish_stream,email'
      });
  }
  </code></pre>