“无法加载资源”使用Facebook的示例代码 [英] "Failed to load resource" using Facebook's example code

查看:75
本文介绍了“无法加载资源”使用Facebook的示例代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Facebook JS SDK的文档中运行第一个例子。我创建了一个新的应用程序,创建了一个名为facebookTest.html的空白文档,粘贴在示例的代码中,并插入了新应用程序的应用程序ID。代码如下:

 < html> 
< head>
< title>使用Facebook登录< / title>
< div id =fb-root>< / div>
< script>
window.fbAsyncInit = function(){
// init FB JS SDK
FB.init({
appId:'我的应用程序ID',//应用程序ID从应用程序控制台
status:true,//检查初始化时的登录状态
cookie:true,//设置会话cookie以允许您的服务器访问会话
xfbml:true //在此页面上解析XFBML标签?
});

//附加的初始化代码如添加事件侦听器在这里

};

//异步加载SDK的源
//请注意,调试版本正在积极开发,并且
//可能包含过于严格的类型检查。
//请使用错误工具报告此类错误。
(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 = document.location.protocol +/ /connect.facebook.net/en_US/all+(debug?/ debug:)+.js;
ref.parentNode.insertBefore(js,ref);
} document,/ * debug * / false));
< / script>

当我加载页面时,在Javascript控制台上会收到以下错误消息:



无法加载资源



我做错了什么? / p>

编辑:当我在之前添加 document.location.protocol // connect。根据建议的此处,facebook.net /...\",屏幕保持空白,并且控制台显示以下内容:

  GET文件://connect.facebook.net/en_US/all.js 

所有这些代码是应该做的吗?还是还是失败?

解决方案

这里有一些情况错误:


  1. 需要更改 js.src 赋值给:
    js.src = https://connect.facebook.net/en_US/all.js;


  2. Facebook不再支持JS SDK调用由本地文件制作,该脚本必须在具有 http:// https:// URI,根据 Facebook上的此错误报告。我需要将文件上传到Web服务器,相应地更改画布URL,然后重新测试。



I'm trying to run the first example from the documentation of the Facebook JS SDK. I created a new app, created a blank document called "facebookTest.html", pasted in the code from the example, and plugged in the new app's App ID. Code as follows:

<html>
<head>
<title>Login with facebook</title>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : 'my app ID', // App ID from the App Dashboard
      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 = document.location.protocol+"//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
     ref.parentNode.insertBefore(js, ref);
   }(document, /*debug*/ false));
</script>

When I load the page, on the Javascript console I get the following error message:

Failed to load resource

What am I doing wrong?

EDIT: When I add document.location.protocol before the "//connect.facebook.net/...", as suggested here, the screen stays blank, and the console shows the following:

GET file://connect.facebook.net/en_US/all.js  

Is that all this code is supposed to do? Or is it still failing?

解决方案

There were a couple things wrong here:

  1. needed to change js.src assignment to: js.src="https://connect.facebook.net/en_US/all.js";

  2. Facebook no longer supports JS SDK calls made from a local file, the script has to be run on a file with an http:// or https:// URI, as per this bug report on Facebook. I will need to upload the file to a web server, change the canvas URL accordingly, and retest.

这篇关于“无法加载资源”使用Facebook的示例代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆