我似乎无法理解为什么我没有被重定向到适当的页面。它当然存在。屏幕弹出并在一秒钟后消失,而不是重定向我。
<div id='fb-root'></div>
<script>
window.fbAsyncInit = function()
{
FB.init({
appId: 'ID',
status: true,
cookie: true,
xfbml: true
});
FB.Event.subscribe('auth.login', function(response)
{
window.location = '/fb_redirect.php';
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = '//connect.facebook.net/en_US/all.js#xfbml=1&appId=ID';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class='fb-login-button' data-show-faces='false' scope='email' data-width='200' data-max-rows='1'></div>
答案 0 :(得分:0)
不要执行FB.Event.subscriber
,请尝试以下操作:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
if ( typeof response != 'undefined' && typeof response.authResponse != 'undefined' ) {
window.location = '/fb_redirect.php';
}
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
如果用户已登录,该函数将返回connected
,然后它会将它们重定向到您想要的任何页面。对于需要首次登录的用户,您可以保留FB.Event.subscriber
功能,上述代码适用于返回用户。