我的网站上有Facebook登录问题。下面的代码是我的FB-Connect代码。代码的评论部分标志着我进入我的网站。我的问题是,当我“重新激活”这段代码时,它每次我访问页面时都会立即记录我。但我想在用户点击“使用Facebook登录”-Button时登录用户。当我点击Facebook登录按钮时,Popup显示并且没有任何反复发生..
当我点击FB-Connect按钮时,我可以以某种方式调用JS函数吗?
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxxxxxxxxxxxx', // 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;
var uid = response.authResponse.userID;
//this part of the code below redircts me to the part, where i login to my system.
/*var accessToken = response.authResponse.accessToken;
$.ajax({
type: 'POST',
url: '/?eID=login',
data: $(this).serialize(),
success: function(msg) {
alert("LOGIN");
$('#content').load('/live-session/tickets/');
}
});*/
}});
答案 0 :(得分:5)
点击fb connect按钮需要使用FB.login功能,不要使用FB.getLoginStatus
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 + '.');
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
});
来自Doc
FB.getLoginStatus允许您确定用户是否已登录 Facebook并已验证您的应用程序。
因此,如果您不想检查用户是否已登录页面加载,请不要调用此
当我点击Facebook登录按钮时,Popup显示并且没有任何反复发生..
如果您已经授权应用程序并进行了身份验证,则facebook不会再次要求您登录和授权