Facebook SDK没有;t负载..all.js GET失败

Facebook SDK doesn't load...all.js GET failing

本文关键字:all js GET 失败 负载 SDK 没有 Facebook      更新时间:2023-09-26

我使用的代码与此处中提供的代码相同

<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function() {
    console.log('got here');
    FB.init({
    appId      : '197112467099018', // App ID
    channelUrl : '//WWW.MYDOMAIN.COM/channel.html', // Channel File
    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>

Chrome的控制台告诉我脚本加载失败(GET失败),有2个错误标记为(匿名函数)

它指出的错误是:

   ref.parentNode.insertBefore(js, ref);
   }(document));

有人能帮我弄清楚这些线怎么了吗?

我在chrome中使用重影,没有注意到它阻止了"facebook连接"。我打赌你也有类似的问题。刚刚发生在我身上。

  1. 请确保您在web服务器的上下文中运行此代码(浏览器URL以http:或https:协议开头),而不是从本地文件(不应以file:开头)。

  2. 请确保将该代码段放在<body>中,而不是<head>中。

Avast Online Security是一个浏览器扩展/插件,取决于您使用的浏览器版本,刚刚发布了一个新版本(2014),阻止社交脚本运行。。。基本上,他们已经瞄准了google+,facebook,twitter CDN脚本并屏蔽了它们。。。默认情况下为ON。。。有趣的是,选项说它会阻止人们跟踪你,但它完全忽略了谷歌分析脚本。LOL avast。。。不错的尝试。。。

Facebook肯定已经更改了该示例代码。我最初认为这是因为js.src以//开头,但js SDK可能会自动附加http:或https:

我的代码类似于:

 <script type="text/javascript">
    var fbAppId = 'xxxxxxxxxx'
    window.fbAsyncInit = function () {
        FB.init({ appId: fbAppId, status: true, cookie: true,
            xfbml: true
        });
    };
    (function () {
        var e = document.createElement('script');
        e.type = 'text/javascript';
        e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
    } ());   
</script>

注意我的url前面有document.location.procol。

试试看是否有帮助。我的代码显然是一个较旧但仍在工作的版本。

检查是否有防病毒插件/扩展。我有Avast,它有一个浏览器插件/扩展。我更改了社交网络设置,它对我有效。