Facebook Login Button callback function

authentication, facebook, facebook-graph-api, javascript

Solution

You need to use FB.login function on click on fb connect button and don't use FB.getLoginStatus

 FB.login(function(response) {
   if (response.authResponse) {
     console.log('Welcome!  Fetching your information.... ');
     FB.api('/me', function(response) {
       console.log('Good to see you, ' + response.name + '.');
     });
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 });

From Doc

FB.getLoginStatus allows you to determine if a user is logged in to Facebook and has authenticated your app.

So, if you don't want to check whether user has logged in on page load, don't call this

When I clicks the facebook login button a Popup shows up and nothing happens..

If you had already authorized the app and authenticated, facebook wont ask you again for login and authorization

Problem

I got a Problem with the Facebook Login on my Website. The Code Below is my FB-Connect Code. The commented part of the code sign's me in to my Website. My Problem is when i "reactivate" this code it logs me in instandly everytime i visit the page. But i want to log the user in when he clicks the "Login with Facebook"-Button. When I clicks the facebook login button a Popup shows up and nothing happens.. Can i somehow call a JS function when i click the FB-Connect button? ``` <script> window.fbAsyncInit = function() { FB.init({ appId : 'xxxxxxxxxxxxxxxxxx', // App ID status : true, cookie : true, xfbml : true, oauth : true, }); var login = false; FB.getLoginStatus(function(response) { if (response.status === 'connected') { console.log('connected'); login=true; var uid = response.authResponse.userID; //this part of the code below redircts me to the part, where i login to my system. /*var accessToken = response.authResponse.accessToken; $.ajax({ type: 'POST', url: '/?eID=login', data: $(this).serialize(), success: function(msg) { alert("LOGIN"); $('#content').load('/live-session/tickets/'); } });*/ }}); ```

Original source