简体   繁体   中英

Issue with FB Javascript login SDK

My FB login works almost fine. The only problem is when i log in the first time, the response status === unknown. de popup closes and there is no redirect because the status is unknown, ok.. the second login attempt i press the fb login button, popup opens and closes again and the redirect take place. in the browser there are 2 fbsr_{appid} cookies. and then the status === connected.

function fblogin() {
FB.init({
  appId      : '{ my app id }',
  cookie     : true, 
  xfbml      : true,  
  version    : 'v3.2'
});

FB.login(function (response) {

        console.log(response);

        if (response.status === 'connected') {  
            
        FB.api('/me',  { locale: 'en_US', fields: 'email,first_name,last_name,id' },
        function (response) {

              window.location.href = '/page_to_redirect_to?UserNAME=' + response.first_name + '%20' + response.last_name + '&UserEMAIL=' + response.email  + '&UserID=' + response.id;

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


 (function(d, s, id) {
   var js, fjs = d.getElementsByTagName(s)[0];
   if (d.getElementById(id)) return;
   js = d.createElement(s); js.id = id;
   js.src = "//connect.facebook.net/en_US/sdk.js";
   fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));


  <button onclick="fbLogin();" class="fb connect">Sign in with Facebook</button>

According to the documentation the unknown status happens when FB can't confirm whether the user is logged in and gave permissions to your app. So it looks like this can be a normal situation to receive that status, and the user should try to log in again.

Another thing is why do you always get this unknown status in your first request. Not sure why this is happening.

By the way - I think you're using an old version of the Facebook API. (currently v10 is newest)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM