2012-09-04 114 views
-1

我使用Facebook的JavaScript的SDK的登錄按鈕,在我的網站能正常工作,但我缺少兩個用例Facebook登錄循環周圍

  1. 每當Facebook的cookie是可用時,它是從index.php來重定向event.php頁面,即使我正在觸發FB.login()函數的點擊事件。
  2. 當用戶點擊退出按鈕在我的網站我正在index.php文件重定向它,加載index.php頁面後,它再次被重定向到event.php頁

這裏是我的代碼中的index.php

<script src="//connect.facebook.net/en_US/all.js"></script> 
<script> 
FB.init({ 
    appId  : '375834632488230', // App ID 
    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 
FB.Event.subscribe('auth.login', function(response) { 
window.location="http://mysite.com/event.php"; 

}); 

function doLogin(){ 
console.log("clicked on fb"); 
FB.login(function(response) { 
    if (response.session) { 
    FB.api('/me?fields=email,location,name,first_name,last_name,picture', 
    function (response) {  }); 
    } 
} , {scope:'email'}); 
} 

</script> 
<a href="#" id="fblogin" class="signinfacebook" onclick="doLogin()">Sign in with 
Facebook</a> 

回答

0

回答我的問題

中刪除此代碼:

FB.Event.subscribe('auth.login', function(response) { 
    window.location="http://mysite.com/event.php"; 
}); 

這不應該在這種情況下使用。

然後加入這一行中FB.Login()功能:

if(response.status=='connected'){ 
    window.location="http://mysite.com/event.php"; 
} else { 
    console.log("login failed"); 
} 

我想這應該能正常運行