FB.Event.subscribe('auth.login') won't trigger e
FB.Event.subscribe('auth.login') won't trigger everytime?
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'MY_APP_ID',
status : true,
cookie : true,
xfbml : true
});
FB.Event.subscribe('auth.login', function(response) {
$.ajax({
url: "http://example.com/fbconnect",
success: function(){
window.location.reload();
}
});
});
};
(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>
<div class="fb-login-button" data-perms="email,user_birthday,user_hometown,user_location">Login with Facebook</div>
它只适用于两种情况:
- 当用户未登录并登录facebook时触发。
- 当用户登录但尚未授权应用程序时,它会触发。
第三种不工作的情况是当用户登录并且他已经被授权使用应用程序时,FB.Event.subscribe('auth.login')
不会触发!!
我遇到了和你一样的事情,我发现了一个函数,"getLoginStatus",这可能是你感兴趣的。
当用户已经登录并授予应用程序所有权限时,则不需要再次登录,因此不会触发该事件。
然而,如果"getLoginStatus"的响应是"connected",当用户已经登录并授予应用程序所有权限时,你可以做你想做的事情。
完整的脚本可能看起来像这样:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'APPID', // App ID
channelUrl : 'CHANNEL_URL', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and connected to your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
FB.api('/me', function(response) {
if (response.name != undefined ) {
console.log("Welcome, " + response.name);
}
});
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but not connected to the app
} else {
// the user isn't even logged in to Facebook.
}
});
// Additional initialization code here
};
// 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>
在这里得到了完全相同的问题,它让我发疯。不喜欢Facebook Javascript SDK atm。
FB.init()中的状态检查真的很复杂,当你在页面上放置facebook评论时,它会变得更加困难…
我刚刚测试的一个解决方案是拥有自己的登录按钮并使用FB.login()方法,在那里您可以挂钩到回调(这将取代您的验证代码)。登录事件).
window.fbAsyncInit = function () {
FB.init({
...
});
$('#fb-login-button-custom').show().click(function () {
var scopeList = $(this).data('scope');
FB.login(function (response) {
alert('FB.login callback');
console.log(response);
document.location.href = document.location.pathname + '?fblogin=1';
}, { scope: scopeList });
});
});
默认登录事件实际上只在用户授权应用程序时触发。因此,当注销用户时,您可以撤销授权。但每次登录时,他们都必须"允许"该应用。
使用FB.Event.subscribe('auth.statusChange', handleStatusChange);
将通知您状态更改…
希望有所帮助
相关文章:
- 为什么要从focus()更改为trigger('focus')
- AngularJS ng include won'不知什么原因不起作用
- Trigger.io Collaboration
- 通过php添加到变量won'不起作用
- vue-js-单选按钮won't默认情况下使用v-model属性进行检查
- calling.trigger(“click”),它在ajax调用返回的javascript代码中
- 在html中显示javascript变量won'不起作用
- 在javascript createElement上调用.trigger
- 在 iPad 上调试 trigger.io 应用
- 在此代码中需要 .trigger(“更改”)是什么?
- RefluxJS存储可以在调用trigger()时指示哪个属性已更改吗?
- jQuery .trigger() 多个事件
- trigger('create') 在 Chrome 中正确呈现,但在 Android 模拟器中无法正确呈现
- 将 jQuery trigger() 与 hoverIntent 一起使用
- 在隐藏值上调用 jQuery .trigger('change') 会破坏与 KNOCKOUT 相关的可观察性
- 未捕获的类型错误:document.getElementById(..).value.trigger不是函数
- 在Trigger.io移动应用程序中启用缩放
- Trigger.io::未处理的意向结果
- iFrame getFocus won't trigger
- FB.Event.subscribe('auth.login') won't trigger e