Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Facebook 未捕获类型错误:无法调用方法';班次';空的_Facebook_Facebook Javascript Sdk_Requirejs - Fatal编程技术网

Facebook 未捕获类型错误:无法调用方法';班次';空的

Facebook 未捕获类型错误:无法调用方法';班次';空的,facebook,facebook-javascript-sdk,requirejs,Facebook,Facebook Javascript Sdk,Requirejs,我只是在Chrome上收到这个消息。Firefox运行得很好。我一直在调试,试图找出这个错误发生的时间点,但似乎无法确定。确切的消息是all.js:57中的“uncaughttypeerror:cannotcallmethod'shift'of null” 此外,我还将注意到其他一些可能对您有所帮助的事情: 我将SDK作为requirejs模块加载。我也尝试过以“正常方式”加载它,但结果是一样的 它不会在本地发生,只在我们的暂存服务器上发生。这让我觉得它在SDK加载过程中与延迟有关 这只发生在

我只是在Chrome上收到这个消息。Firefox运行得很好。我一直在调试,试图找出这个错误发生的时间点,但似乎无法确定。确切的消息是all.js:57中的“uncaughttypeerror:cannotcallmethod'shift'of null”

此外,我还将注意到其他一些可能对您有所帮助的事情:

  • 我将SDK作为requirejs模块加载。我也尝试过以“正常方式”加载它,但结果是一样的
  • 它不会在本地发生,只在我们的暂存服务器上发生。这让我觉得它在SDK加载过程中与延迟有关
  • 这只发生在Chrome上。Firefox和Safari一样工作。Safari中唯一的区别是,我看到一个类似的错误,指出这是一个类型问题。那里的消息是“'null'不是对象(评估'queue.shift`)”@debug.js:2712,但它不会破坏应用程序

这里的任何帮助和/或见解都将非常有用

对不起,我能帮上很多忙,但我也有同样的问题,可能有助于解决这个问题

正在加载JS likeso:

<script src='//connect.facebook.net/en_US/all.js'></script> 

“这不是在本地发生的,只是在我们的暂存服务器上。这让我 认为它在SDK加载过程中与延迟有关。”

我倾向于同意。这个错误似乎只是偶尔发生。此外,我偶尔会遇到curloptipresolve未定义错误。似乎所有这些都与连通性有关

这些解释了调用SDK的另一种方式,这对我很有用。我还没有测试它,但我认为通道文件可以让您在本地测试它,这非常好

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : 'YOUR_APP_ID', // App ID from the App Dashboard
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File for x-domain communication
      status     : true, // check the login status upon init?
      cookie     : true, // set sessions cookies to allow your server to access the session?
      xfbml      : true  // parse XFBML tags on this page?
    });

    // Additional initialization code such as adding Event Listeners goes here

  };

  // Load the SDK's source Asynchronously
  // Note that the debug version is being actively developed and might 
  // contain some type checks that are overly strict. 
  // Please report such bugs using the bugs tool.
  (function(d, debug){
     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" + (debug ? "/debug" : "") + ".js";
     ref.parentNode.insertBefore(js, ref);
   }(document, /*debug*/ false));
</script>

window.fbAsyninit=函数(){
//初始化FBJSSDK
FB.init({
appId:'您的应用程序\ ID',//应用程序仪表板中的应用程序ID
channelUrl:'//WWW.YOUR_DOMAIN.COM/channel.html',//用于x域通信的通道文件
status:true,//在初始化时检查登录状态?
cookie:true,//设置会话cookie以允许服务器访问会话?
xfbml:true//是否解析此页面上的xfbml标记?
});
//附加的初始化代码(如添加事件侦听器)如下所示
};
//异步加载SDK的源代码
//请注意,调试版本正在积极开发中,可能
//包含一些过于严格的类型检查。
//请使用bug工具报告此类bug。
(功能(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”+(debug?/debug):“)+”.js”;
ref.parentNode.insertBefore(js,ref);
}(文档,/*debug*/false));

重写调用SDK脚本对我有帮助。它需要被称为它的解释

首先,我试图简单地用id='fasebook-jssdk'向head元素添加一个脚本,但方法'shift'出现了一个错误。然后我按照facebook的建议重写了它,没有使用FB.init()。但是错误一直在发生,直到我添加了FB.init()调用。现在它工作正常了

为了解决这个问题,我找到了一个调试版本的'all.js',我发现错误出现在以下代码中:

function flush() {
  if (!queue) {
    return;
  }

  var fn;
  while (fn = queue.shift()) {
    fn();
  }
  queue = null;
}

其中queue是一个函数数组。我不知道原因,但现在,当脚本运行正常时,我真的不需要。也许有比我更谨慎的人会发现。

我也有类似的问题。这对我来说已经解决了。这些症状是:

  • 本地主机上没有问题
  • 在服务器(AmazonS3)上,偶尔会出现“uncaughtTypeError:无法调用null的'shift'方法”
  • 解决方案:

    我把FacebookSDK和FBAsyninit处理程序的包含顺序搞乱了。在包含用于处理SDK加载的脚本之后,应该包含SDK。否则,SDK可能会在其加载事件的处理程序注册之前加载

    <script src="Your script with fbAsyncInit here"> </script>
       <div id="fb-root"></div>
        <script>(function(d, s, id) {
          var js, fjs = d.getElementsByTagName(s)[0];
          if (d.getElementById(id)) return;
          js = d.createElement(s); js.id = id;
          js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=200817623450198";
          fjs.parentNode.insertBefore(js, fjs);
          }(document, 'script', 'facebook-jssdk'));
        </script>
      <div id="fb-root"></div>
      </body>
    
    
    (功能(d、s、id){
    var js,fjs=d.getElementsByTagName[0];
    if(d.getElementById(id))返回;
    js=d.createElement;js.id=id;
    js.src=“//connect.facebook.net/en_US/all.js#xfbml=1&appId=200817623450198”;
    fjs.parentNode.insertBefore(js,fjs);
    }(文档“脚本”、“facebook jssdk”);
    
    您是否找到了此问题的解决方案?我在Chrome上随机发现了同样的错误。至少这个问题需要说明你是如何加载Facebook代码的。目前,你有一大堆答案都是猜测。