使用Facebook登录插件加载已连接的FB帐户后重新加载页面
我有以下代码:使用Facebook登录插件加载已连接的FB帐户后重新加载页面,facebook,plugins,facebook-javascript-sdk,facebook-login,Facebook,Plugins,Facebook Javascript Sdk,Facebook Login,我有以下代码: <html xmlns:fb="http://www.facebook.com/2008/fbml"> <head> <title></title> </head> <body> <div id="fb-root"></div> <script> window.fbAsyncInit = function() { FB.init({
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title></title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'APP_ID', // 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
};
// 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";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
<fb:login-button show-faces="true" width="370" max-rows="5" scope="email">Log In with Facebook</fb:login-button>
</body>
</html>
我使用Facebook登录应用程序。
页面刷新,显示我已登录。
如果我再次刷新或加载页面,Facebook将加载插件。大约10秒钟后,页面将重新加载。
是我初始化错误,还是Facebook就是这么做的
编辑:
我有时会出现以下错误:
1个XFBML标记未能在30000ms内呈现
从中找到临时修复程序
我不知道为什么会这样,但我很高兴它解决了这个问题。有人知道更好的修复方法吗?尝试添加频道文件
FB.init({
appId : 'APP_ID', // App ID
status : true, // check login status
channelUrl : '//WWW.MY_DOMAIN.COM/channel.html', // Channel File
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
通道文件将仅包括:
<script src="//connect.facebook.net/en_US/all.js"></script>
参考:
xfbml呈现似乎工作不正常,请尝试使用HTML版本
<div class="fb-login-button" show-faces="true" width="370" max-rows="5" scope="email">Login with Facebook</div>
当我使用HTML版本时,我仍然可以使用并订阅xfml.render吗?是的,你可以,它会触发事件,但是我不确定你会使用它做什么。它是否用作onload委托?页面上的某些元素只有在插件呈现后才能显示。
FB.login(function(response) {
// handle the response
}, {scope: 'email'});