我在我的网站上使用 facebook javascript SDK 作为登录按钮,它工作正常,但我在两个用例中丢失了
- 每当 facebook cookie 可用时,它就会从 index.php 重定向到 event.php 页面,即使我正在触发 FB.login() 函数点击事件。
- 当用户单击我网站上的注销按钮时,我将其重定向到 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>