我有一个可以使用Facebook登录的网站。
问题发生在用户第一次访问网站时(或清除cookie后)。
用户流如下:
- 用户点击"注册Facebook"
- 用户被重定向到Facebook身份验证
- 如果用户接受,他/她将被重定向到"注册"页面
问题是如果用户是第一次这样做,他们总是被重定向回主页。
对于这个url ,只有2种可能的视图可以给出
- 注册页面,只有一些表单数据作为参数发送
- DB持久化成功后的警报框
因此,我已经排除了PHP作为重定向的可能原因。
我已经包含了管理Facebook交互的JavaScript。
所有其他相关代码都可以在页面的HTML中找到。
该页面位于http://trioisrael.com
function fb_login(){
FB.login(function(response) {
if (response.authResponse) {
window.location = "http://trioisrael.com/signup"
//console.log(response); // dump complete info
access_token = response.authResponse.accessToken; //get access token
user_id = response.authResponse.userID; //get FB UID
FB.api('/me', function(response) {
user_email = response.email; //get user email
// you can store this data into your database
});
} else {
//user hit cancel button
alert('We use facebook to make sure that everyone is really who they say they are');
}
}, {
scope: 'user_photos,user_birthday'
});
}
在为window.location
(当然应该是window.location.href
)分配一个新值后尝试做其他事情是没有意义的。
如果你想在登录后做更多的事情,请在将用户重定向到其他地方之前先做。