Javascript 未激发FB.Event.subscribe auth.login
我正在使用facebook javascript sdk连接到facebook 但是FB.Event.subscribe auth.login未被激发 这是我正在使用的代码Javascript 未激发FB.Event.subscribe auth.login,javascript,facebook,facebook-javascript-sdk,Javascript,Facebook,Facebook Javascript Sdk,我正在使用facebook javascript sdk连接到facebook 但是FB.Event.subscribe auth.login未被激发 这是我正在使用的代码 window.fbAsyncInit = function() { // init the FB JS SDK FB.init({ appId : 'xxxxxxxxx', // App ID from the app dashboa
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : 'xxxxxxxxx', // App ID from the app dashboard
channelUrl : 'MychannelUrl', // Channel file for x-domain comms
status : true, // Check Facebook Login status
xfbml : true // Look for social plugins on the page
});
// Additional initialization code such as adding Event Listeners goes here
FB.Event.subscribe('auth.login', function(response) {console.log('event fired');
if(response.status === 'connected') { console.log('connected'); }
});
}
// Load the SDK asynchronously
(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/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
window.fbAsyninit=function(){
//初始化FBJSSDK
FB.init({
appId:'xxxxxxxxx',//应用程序仪表板中的应用程序ID
channelUrl:'MychannelUrl',//用于x域通信的通道文件
状态:true,//检查Facebook登录状态
xfbml:true//在页面上查找社交插件
});
//附加的初始化代码(如添加事件侦听器)如下所示
订阅('auth.login',函数(响应){console.log('Event fired');
if(response.status==='connected'){console.log('connected');}
});
}
//异步加载SDK
(功能(d、s、id){
var js,fjs=d.getElementsByTagName[0];
if(d.getElementById(id)){return;}
js=d.createElement;js.id=id;
js.src=“//connect.facebook.net/en_US/all.js”;
fjs.parentNode.insertBefore(js,fjs);
}(文档“脚本”、“facebook jssdk”);
好的,不要使用auth.login,而是使用auth.statusChange
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.status === 'connected') {
//the user is logged and has granted permissions
} else if (response.status === 'not_authorized') {
//ask for permissions
} else {
//ask the user to login to facebook
}
});
请记住,这仅在用户状态发生更改时触发,因此如果要在第一次运行时获取用户的状态,请使用
FB.getLoginStatus()
函数。此函数给出的响应与auth.statusChange
事件、connected
和not\u authorized
中的响应相同,而不是使用auth.login使用auth.statusChange
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.status === 'connected') {
//the user is logged and has granted permissions
} else if (response.status === 'not_authorized') {
//ask for permissions
} else {
//ask the user to login to facebook
}
});
请记住,这仅在用户状态发生更改时触发,因此如果要在第一次运行时获取用户的状态,请使用FB.getLoginStatus()
函数。此函数给出的响应与auth.statusChange
事件、connected
和not\u authorized