我正在我的网站上实施facebook身份验证(注册+登录)。一切正常,除非按钮显示即使我已登录。提前致谢
<h1 id="welcome">Welcome to my website</h1>
<div id="fb-root"></div>
<span id="fb-login" class="hidden">
<fb:login-button registration-url="http://lemiart.com/register.php"></fb:login-button>
</span>
<script src="https://connect.facebook.net/en_US/all.js#appId=306738122732711&xfbml=1"></script>
<script type="text/javascript">
FB.init({appId: '306738122732711', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(){
loggedIn();
});
FB.getLoginStatus(function(response){
if (response.session){
// user logged in. Let the auth.login subscription handle this
} else {
loggedOut();
}
});
loggedIn = function() {
FB.api('/me', function(response) {
var welcome = document.getElementById('welcome');
if (welcome) welcome.innerHTML += ' ' + response.id;
document.getElementById('fb-login').className = "hidden";
})
}
loggedOut = function() {
document.getElementById('fb-login').className="";
}
</script>
答案 0 :(得分:0)
您当前的实施将始终提示用户登录。您可能需要做的是以下内容:
将一个回调函数写入FB.init,然后检查用户是否登录到您的应用程序,然后决定是否要显示fb:login-button。
它看起来像这样:
window.fbAsyncInit = function() {
FB.init({
//...
});
FB.getLoginStatus(function(response){
FB.getLoginStatus(function(response){
if (response.session){
// user logged in. Let the auth.login subscription handle this
} else {
loggedOut();
}
});
};