我正在尝试运行 Facebook JS SDK 文档中的第一个示例。我创建了一个新应用程序,创建了一个名为“facebookTest.html”的空白文档,粘贴示例中的代码,然后插入新应用程序的应用程序 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
我做错了什么?
编辑:当我按照
here的建议在
document.location.protocol
之前添加"//connect.facebook.net/..."
时,屏幕保持空白,控制台显示以下内容:
GET file://connect.facebook.net/en_US/all.js
这就是所有这些代码应该做的事情吗?还是仍然失败?
只需禁用广告拦截, 它对我有用
这里有一些问题:
需要将
js.src
分配更改为:
js.src="https://connect.facebook.net/en_US/all.js";
Facebook 不再支持从本地文件进行 JS SDK 调用,脚本必须在具有
http://
或 https://
URI 的文件上运行,根据 Facebook 上的错误报告。我需要将文件上传到网络服务器,相应地更改画布 URL,然后重新测试。首先你需要将 http 或 https 附加到 js.src url
其次,您需要将 html 文件托管在服务器上。
如果您的网址包含“广告”、“广告”、“双击”、“点击”或类似内容……
例如:
GET googleads.g.doubleclick.net/pagead/id
static.doubleclick.net/instream/ad_status.js
…然后广告拦截器就会拦截它。
前往 Facebook 开发者并添加您的网站域名并获取 ID 并粘贴到下面:
appId : 'my app ID', // App ID from the App Dashboard
添加一件事我在这里没有看到:如果您在 Firefox 中进行调试,请在开发时禁用增强跟踪保护和 Facebook 容器。
只需禁用您使用的任何类型的广告拦截器扩展即可正常工作。
值得检查任何类型的广告拦截器扩展。 错误
net::ERR_BLOCKED_BY_CLIENT
正是与此相关。
您可以尝试多种解决方案来修复此错误:
这是一篇关于它的完整文章: https://www.keycdn.com/support/how-to-solve-err-blocked-by-client