我对Facebook连接有一点问题,关于生日许可。
在我的html身上:
<div class="fb-login-button" scope="user_birthday, user_about_me" perms="email,user_birthday"> Login with Facebook </div>
在标题上,对于jS,我有:
<script>
// Additional JS functions here
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXX', // App ID
channelUrl : '//connect.facebook.net/en_US/all.js', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional init code here
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// connected
FB.api('/me??accessToken='+response.authResponse.accessToken, function(user) {
var monthfb = user.birthday.substr(0,2);
var dayfb = user.birthday.substr(3,2);
var yearfb = user.birthday.substr(6,4);
$("input[id=year]").val(monthfb);
$("input[id=month]").val(dayfb);
$("input[id=day]").val(yearfb);
$("a.age_gate_submit").click();
alert('1');
console.log(user);
//$.cookie('age_gate', 'gohome',{ expires: 99 });
window.location = "home.html";
});
}
});
};
function login() {
FB.login(function(response) {
if (response.authResponse) {
// connected
FB.api('/me??accessToken='+response.authResponse.accessToken, function(user) {
var monthfb = user.birthday.substr(0,2);
var dayfb = user.birthday.substr(3,2);
var yearfb = user.birthday.substr(6,4);
$("a.age_gate_submit").click();
alert('2');
//console.log(response.birthday);
console.log(user);
//$.cookie('age_gate', 'gohome',{ expires: 99 });
window.location = "home.html";
});
}
});
}
// 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#xfbml=1&appId=XXXXXXX";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
当我点击我的按钮时,我有一个好的窗口,我接受了FB应用程序,但没有一个函数jS正在调用,所以window.locations不起作用。但是,当我刷新它没关系我可以过生日等...所以问题就在我接受应用程序的那一刻:如何重定向?
答案 0 :(得分:1)
抱歉,你的回答对我没有帮助。 但我找到了解决方案:
我必须实现FB.Event.subscribe(),当一个人接受登录时,此功能有效。