我的页面上的 Facebook 登录出现问题。首先,我仅使用 FB.Login 进行了尝试,但随后我收到以下消息:“当用户已连接时调用 FB.login()。”
所以我添加了 FB.getLoginStatus 但现在它让我在无限循环中登录。即使我已经登录(进入我的系统)并且没有我点击 FB-Connect 按钮。
在我单击 FB-connect 按钮之前,我如何才能实现不登录?
<div id="fb-root"></div>
<script>(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/fb_LT/all.js#xfbml=1&appId=198866780209581";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
window.fbAsyncInit = function() {
FB.init({
appId : "198866780209581", // App ID
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
var login = false;
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
console.log('connected');
login=true;
$.ajax({
type: "POST",
url: "/?eID=login&modus=facebook&fb-login=1",
data: $(this).serialize(),
success: function(msg) {
console.log("LOGIN");
window.location.reload();
}
})
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
}
else{
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
if(login===false)
{
alert('nicht connected');
}
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'email'});
}});
// Additional initialization code here
};
</script>