使用 Facebook SDK,我在尝试将用户连接到我的网站时收到以下控制台错误。 “连接 Facebook”按钮在除 Firefox 之外的所有其他浏览器中都可以正常工作。
我在 innit 配置中有一个 channel URL,我已经确认这个问题发生在没有 Firebug 的 Firefox 安装中。以下是我的代码:
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : 'my_real_app_id',
channelUrl : 'MYURL.com/channel.php',
status: true,
cookie: true,
xfbml : false
});
};
(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));
$(document).ready(function() {
$('a#login-fb').click(function(event) {
event.preventDefault();
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information...');
FB.api('/me', function(response) {
handleFacebookLogin(response);
});
} else {
console.log('User cancelled login or did not fully authorize');
}
}, {scope: 'email, offline_access, user_birthday, publish_stream, publish_actions' });
});
</script>
最佳答案
我通过将上面的 javascript 更改为以下 #fb-root 来解决此问题:
<div id="fb-root"></div>
<script type="text/javascript">
$(document).ready(function() {
window.fbAsyncInit = function() {
FB.init({
appId : 'my_id',
status: true,
cookie: true,
xfbml : false
});
};
(function() {
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
//rest of code here
关于facebook - Firefox 只有 : FB. 在 FB.init() 之前调用了 login(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9763078/