[英]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.