这是我的Facebook连接代码:FB.Event.subscribe不会被调用
<script>
jQuery(document).ready(function($){
$(".fb-login-button").live('click', function() {
console.log('click');
fbEnsureInit(function() {
console.log('EnsureInit');
FB.login(function(response) {
console.log('FB.login');
// redirect will be done
}, {scope: 'email'});
});
});
});
window.fbAsyncInit = function() {
FB.init({
appId : '105224616211361', // App ID
/*channelUrl : '///channel.html', // Channel File // We don't do not to get caching problems with the laguage!*/
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
fbApiInitialized = true;
// whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function(response) {
try {
if (response.status == 'connected') {
console.log('connected');
$.ajax({
type: "POST",
url: "/?eID=login&modus=facebook&fb-login=1",
data: $(this).serialize(),
success: function(msg) {
console.log("LOGIN");
window.location.reload();
}
})
} else {
console.log('not connected');
window.location.reload();
}
} catch(err) {
window.location.reload();
}
});
};
/**
* Make sure that the FB is initialized!
*/
function fbEnsureInit(callback) {
if (!window.fbApiInitialized) {
setTimeout(function() { fbEnsureInit(callback); }, 50);
} else {
if (callback) { callback(); }
}
}
/**
* Load the JS SDK directly from Facebook
*/
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/de_DE/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
的SDK被加载。我能看到FB-按钮,当我点击它的代码工作,直到
console.log('FB.login');
的FB-弹出弹出并没有任何反应......这应该是这种地步:
FB.Event.subscribe('auth.login', function(response) {
应被叫...但它不..任何人都可以帮助我解决这个问题吗?
谢谢。
编辑:
我只注意到这只是发生,当我已经登录到Facebook上。如果我没有登录,登录弹出窗口会弹出两次(!),我可以登录Facebook并调用函数FB.Event.Subscribe。
那么如何才能看到用户是否登录到Facebook并连接到我的应用程序?
为什么Popup调用两次?
删除脚本底部的JS SDK的直接加载功能。 –
如果我这样做,FB按钮的图像不会加载。我只有一个不可点击的文字:“与Facebook连接”。 – MrTouch
我的错误。以为你加载SDK两次。 –