简体   繁体   English

Facebook要求用户即使已经登录也要登录

[英]Facebook asks user to log in even though they're already logged in

I'm having a hard time getting the Facebook JS API to work as described in http://developers.facebook.com/docs/reference/javascript/ 我很难按照http://developers.facebook.com/docs/reference/javascript/中的说明使Facebook JS API正常工作

Specifically, the user seems to get asked to log in even if they are already logged in to Facebook. 具体来说,即使他们已经登录到Facebook,也似乎要求用户登录。 For this I'm doing the following: 为此,我正在执行以下操作:

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '3120012412', // App ID goes here
      channelURL : '//WWW.qy.ORG/channel.php', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      oauth      : true, // enable OAuth 2.0
      xfbml      : true  // parse XFBML
    });

    // Additional initialization code here
    FB.login(function(response) {
    if (response.authResponse) {
       alert('Welcome!  Fetching your information.... ');
       FB.api('/me', function(response) {
       alert('Good to see you, ' + response.name + '.');
       alert('response' + response);

       FB.logout(function(response) {
         alert('Logged out.');
       });
     });
    } else {
      alert('User cancelled login or did not fully authorize.');
   }
 }, {scope: 'email'});
  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     d.getElementsByTagName('head')[0].appendChild(js);
   }(document));
</script>

I also tried: 我也尝试过:

FB.getLoginStatus(function(response) {
   if (response.authResponse) {
     // logged in and connected user, someone you know
   } else {
     // no user session available, someone you dont know
   }
});

This also fails even when I'm already logged in to Facebook. 即使我已经登录到Facebook,这也将失败。

What should I do if I want the user to go through the minimum hassle, for just basic access to public information? 如果我希望用户仅需基本访问公共信息,就可以通过最小的麻烦该怎么办? I understand they have to authorize the basic access, but it shouldn't ask them repeatedly should it? 我知道他们必须授权基本访问权限,但是不应重复询问他们吗?

Your first code chunk is logging the user in, then immediately logging them out again - so you probably aren't logged in if you have been running this a few times. 您的第一个代码块是登录用户,然后立即将其再次注销-因此,如果您已经多次运行此代码,则可能没有登录。 Remove the FB.logout block and try it again to see if it makes a difference. 删除FB.logout块,然后再次尝试查看它是否有所不同。

Another thing to remember (and probably the reason your second example isnt working) is although you are logged into facebook.com, you have to be logged in to your own domain via FB.login . 要记住的另一件事(可能是第二个示例无法正常工作的原因)是,尽管您登录了facebook.com,但必须通过FB.login登录到自己的域。 getLoginStatus will check for your fbsr_ cookie and consider you logged in if it is there, but you must already have the cookie, from calling FB.login first. getLoginStatus将检查您的fbsr_ cookie,并考虑是否已登录,但您必须已经具有该cookie, FB.login首先调用FB.login

So I suggest using this: 所以我建议使用这个:

    // Additional initialization code here
    FB.login(function(response) {
       if (response.authResponse) {
          alert('Welcome!  Fetching your information.... ');
          FB.api('/me', function(response) {
             alert('Good to see you, ' + response.name + '.');
             alert('response' + response);
          });
       } else {
          alert('User cancelled login or did not fully authorize.');
       }
    }, {scope: 'email'});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于 Facebook 好友邀请的 GameRequestDialog 始终要求登录,即使用户已经登录 - GameRequestDialog for Facebook friend invitation always asks for login, even if user was already logged in 即使用户已登录,如何强制用户重新输入Facebook密码 - How to force the user to re-enter facebook password even though he/she is logged in 即使他们没有登录,用户也应该查看我的Facebook Wall页面? - User should view my facebook Wall page, even though they are not logged in? Facebook PHP SDK-即使从Facebook注销,用户仍显示为登录Web应用程序 - Facebook PHP SDK - User still shows as logged in on web app even though logged out of Facebook Facebook“apprequest”对话框要求登录 facebook,因为应用程序已经将其登录到 facebook - Facebook "apprequest" dialog asks for facebook login where as app is already logged it to facebook 即使我登录到Facebook,Facebook会话也已过期 - Facebook session is expired even though I am logged in to facebook 登录后重新授权Facebook用户 - Re-Authenitcating a facebook user once logged in 无法识别已登录的Facebook用户 - don't recognize a facebook user already logged in Android facebook sdk 4:检查用户是否已登录 - Android facebook sdk 4: check if user is already logged in 如何查看已经登录Facebook的用户? - How to check user already logged in facebook?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM