简体   繁体   中英

FB.login is always asking my password (even if I'm already logged in)

I'm playing with Facebook Javascript SDK in order to implement a Facebook Connect action. It's already working but the problem is that every time that I try to login again on my application the user has to reenter its facebook password.

I'm sure that there is an option to do this step without entering the password if you are already logged in in facebook (I have seen this in lots of web pages). But how? The documentation http://developers.facebook.com/docs/reference/javascript/FB.login/ and even the source code does not explain how to do this:

"@param opts {Object} ( optional ) Options to modify login behavior."

My implementation right now is like this:

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

     $(".fb_login").hide();
     $(".fb_logout").show();

     FB.api('/me', function(response) {
       register_user(response.id, response.name);
     });

   } else {
     alert('User cancelled login or did not fully authorize.');
   }
 });
 }

And I call to FB.init like this:

FB.init({
  appId      : 'xxxxxxxxx', // App ID
  status     : true, // check login status
  cookie     : true, // enable cookies to allow the server to access the session
  xfbml      : true  // parse XFBML
});

Maybe it has to be a change in the FB.init or some kind of option while calling to FB.login. Any ideas?

Thanks in advance, Raimon Bosch.

There is a method FB.getLoginStatus which you can use to check if user is already loggedin:

FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    var accessToken = response.authResponse.accessToken;
    //you are loggedin 
  } else if (response.status === 'not_authorized') {
    //loggedin but not authorized your app
  } else {
    // the user isn't logged in to Facebook.
  }
});

Did you mean something like that

在PP设置中检查“ 强制Web OAuth重新身份验证” facebbok开发人员>您的应用程序> facebook登录>设置>将“强制Web OAuth重新身份验证”设置为“否”

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