fb.getloginstatus在注销后未启动
fb.getloginstatus not firing after logout
我长期使用Facebook OAuth。
应用程序没有得到getLoginStatus总是得到未知的状态。最近我遇到了这个问题。
工作正常,直到我点击注销按钮。一旦我点击注销按钮,我将面临此登录
问题
这是我的代码
<html>
<head>
</head>
<body>
<div id="fb-root">
<br>
<br>
<button onclick="status();">Login</button>
<br>
<br>
<button onclick="logout();">Log Out</button>
</div>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '137827113065883',
status: true,
cookie: true,
xfbml: true,
});
FB.Event.subscribe('auth.login', function(response) {
alert('logged in');
});
FB.Event.subscribe('auth.logout', function(response) {
alert('logged out');
});
};
function logout() {
FB.logout(function(response) {
console.log('out ' + JSON.stringify(response));
});
}
function status() {
FB.getLoginStatus(function(response) {
console.log(JSON.stringify(response))
if (response.status === 'connected') {
var accessToken = response.authResponse.accessToken;
console.log(accessToken);
} else if (response.status === 'not_authorized') {
var redirect_uri = window.location.protocol + "//" + window.location.host + window.location.pathname;
window.location = "https://facebook.com/dialog/oauth?redirect_uri=" + redirect_uri + "&client_id=137827113065883&response_type=token";
} else {
var redirect_uri = window.location.protocol + "//" + window.location.host + window.location.pathname;
window.location = "https://facebook.com/dialog/oauth?redirect_uri=" + redirect_uri + "&client_id=137827113065883&response_type=token";
}
}, true);
}
//Load the SDK Asynchronous
(function(d) {
var js, id = 'facebook-jssdk',
ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement('script');
js.id = id;
js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
</body>
</html>
谢谢大家,我找到了解决这个问题的方法
通过在注销时删除所有cookie点击。
我用这个删除cookie
document.cookie.split(";").forEach(function(c) {
document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";domain=.example.com;path=/");
});
相关文章:
- 我的jQuery插件参数没有正确启动,遇到了问题
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- 从控制器返回后Ajax启动事件激发
- Meteor上的启动页面
- 如何防止网页加载后自动启动功能
- 如何从JavaScriptInterface启动Navigation Drawer
- window.on.scroll事件未启动
- 单击按钮后启动javascript提示
- 显示具有服务器端自动时间注销的同步倒计时计时器
- 在javaservlet doPost方法中启动线程时,无法返回异常消息
- spine.js在启动时填充模型实例
- 如何在所有ng点击事件AngularJS上启动一个方法
- jQuery悬停在没有鼠标悬停的情况下启动
- SignalR客户端启动连接时如何设置用户
- 我们如何在互联网断开连接或用户关闭选项卡/浏览器时调用注销servlet
- Meteor:在启动时将html注入客户端文件
- Angular UI启动日期选择器问题
- 如何用低音量自动启动Youtube视频(iframe)
- fb.getloginstatus在注销后未启动
- LoginStatus注销未在母版页的某个特定页面中启动javascript