【问题标题】:Facebook SDK doesn't load...all.js GET failingFacebook SDK 未加载...all.js GET 失败
【发布时间】:2012-03-23 22:36:02
【问题描述】:

我正在使用here中提供的相同代码

<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));

谁能帮我弄清楚这些行有什么问题?

【问题讨论】:

    标签: javascript facebook rest get


    【解决方案1】:

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

    【讨论】:

    • 对我来说,是 AdBlock Plus
    • 我已停止在卡巴斯基互联网安全中进行隐私浏览解决了我的问题
    【解决方案2】:
    1. 确保您在 Web 服务器的上下文中运行此代码(您的浏览器 URL 以 http: 或 https: 协议开头),而不是从本地文件(不应以 file: 开头)。

    2. 确保将 sn-p 放入 &lt;body&gt; 而不是 &lt;head&gt;。

    【讨论】:

      【解决方案3】:

      Avast Online Security 是一个浏览器扩展/插件,具体取决于您使用的浏览器版本,刚刚发布了一个新版本 (2014),它可以阻止社交脚本运行...基本上他们已经针对 google+、facebook、twitter CDN 脚本和阻止他们......默认情况下它是开启的...... 有趣的是选项说它阻止人们跟踪你,但它完全忽略了谷歌分析脚本。大声笑 avast...不错的尝试...

      【讨论】:

        【解决方案4】:

        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.protocol。

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

        【讨论】:

        • 我又遇到了这个问题。这次是 AdBlock。真烦人。
        【解决方案5】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-05-09
          • 1970-01-01
          • 2012-09-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-24
          相关资源
          最近更新 更多