我正在尝试运行 Facebook JS SDK 文档中的第一个示例。我创建了一个新应用程序,创建了一个名为“facebookTest.html”的空白文档,粘贴了示例中的代码,并插入了新应用程序的 App ID。代码如下:
<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>
当我加载页面时,在 Javascript 控制台上我收到以下错误消息:
Failed to load resource
我究竟做错了什么?
编辑:当我按照这里的建议添加document.location.protocol
之前,屏幕保持空白,控制台显示以下内容:"//connect.facebook.net/..."
GET file://connect.facebook.net/en_US/all.js
这就是所有这些代码应该做的吗?还是仍然失败?