我已经实现了一个基于Facebook的登录。FB.login运行得很完美,但FB.logout却没有。我尝试过使用不同的FB.init,删除cookie,连续几次运行注销页面,但登录用户的唯一方法是在facebook上登录。
我用于注销的代码是:
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId: '***************',
xfbml: true,
status: true,
cookie: true
});
FB.getLoginStatus();
FB.logout();
</script>有什么想法吗?谢谢
发布于 2013-02-05 21:08:49
您是否尝试过使用FB.logout()按钮单击事件;
function logout(){
FB.logout(function(response) {
// user is now logged out
});
}
<button onclick="logout()">LogOut</button>尝尝这个
发布于 2014-02-28 11:36:31
试着这样做:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID
channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional initialization code here
};
// Load the SDK Asynchronously
(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>然后调用FB.logout()。FB必须在开始之前。
从文件中:
此代码异步加载SDK,因此不会阻止加载页面的其他元素。这对于确保用户和SEO机器人的快速页面加载尤为重要。 上述代码中的URL是协议相对的。这允许浏览器通过包含页面的相同协议(HTTP或HTTPS)加载SDK,这将防止“不安全内容”警告。 分配给window.fbAsyncInit的函数一旦加载就会运行。在加载SDK之后要运行的任何代码都应该放在此函数中和调用FB.init之后。例如,这是测试用户登录状态或订阅应用程序感兴趣的任何Facebook事件的地方。
https://stackoverflow.com/questions/12663511
复制相似问题