我混合使用 PHP SDK 3.x.x 和 Javascript SDK 来登录 Facebook 身份验证。当我们单击登录按钮时,会出现窗口,填写凭据并提交后不会刷新页面。 FB.Event.subscribe('auth.login') 似乎没有触发。有什么问题吗?
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo $facebook->getAppId(); ?>',
oauth : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
最佳答案
据我所知,此登录过程是使用 AJAX 处理的,这就是页面部分刷新的原因。我不知道你面临的问题是什么。在我的解决方案中,我在页面的开头使用了此登录过程,并根据 fb $user 和 $user_profile 定义变量和 session 。后来使用这个变量来更新页面的其他部分。 由于事件未触发,您应该检查 js 并使用 fb 示例来了解他们的 sdk 是如何工作的 希望这对您有帮助。
关于javascript - Facebook认证登录不刷新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8813305/