0

Please note: This is not a duplicate, since the other thread gives a solution that already implemented in my code, yet the problem still persist.

I am using Facebook Javascript SDK with a custom login button:

<button id="login" onclick="javascript:login();">Login Facebook</button>

and javascript:

function login() {
            FB.login(function(response) {

                FB.api('/me', { locale: 'en_US', fields: 'name, email' },
                    function(response) {
                        email = response.email;
                        name = response.name;
                    }
                );

                FB.getLoginStatus(function(response) {
                    user_id = response.authResponse.userID;
                   // alert(user_id);
                });

                console.log('Response goes here! ' + email + ' of ' + name + ' of ' + user_id);

            }, {scope: 'public_profile,email'});
        }

For some reason, I observe this behavior:

When I press login button once I am connected but no console.log is shown.

When I press login button for second time, console.log is shown in console.

After the second button press, console.log is shown with each consecutive button press.

How do I make console.log to show on the very first button press?

Also, I noticed, if I alert user_id (commented out in my code), the console.log is shown on the first button press, right after I close the alert window.

Acidon
  • 1,294
  • 4
  • 23
  • 44

0 Answers0