我正在努力学习教程 here .但是,当我使用看似有效且正确的参数调用 FB.init(...) 时,我收到错误消息:“应用程序配置不允许给定的 URL。:一个或多个给定的 URL 是应用程序设置不允许。它必须与网站 URL 或 Canvas URL 匹配,或者域必须是应用程序域之一的子域。“我已搜索 ( 1 2 ) 以查找此错误,但其他所有人似乎都无法简单地为其 Facebook 应用程序配置设置站点 URL。我 99% 确定我设置正确 - 但显然我做错了什么。
这是导致问题的我的代码。出于隐私原因,我将一些信息替换为“XXX”和“YYY”。
<html>
<body>
<h1>Facebook</h1>
<div id="fb-root"></div>
<script>
// Additional JS functions here
window.fbAsyncInit = function() {
FB.init({
appId : 'XXX', // App ID
channelUrl : '//YYY.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
});
};//window.fbAsyncInit()
// 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 = "http://connect.facebook.net/en_US/all/debug.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
</body>
</html>
请注意,我必须更改教程中给出的示例代码底部附近的 js.src 参数。我怀疑这是导致我的特定问题的原因,但我对教程中代码的质量表示担忧。 (我讨厌教程代码不起作用——这有什么意义?)
您可以在上面的代码中看到我已将域名的根替换为“YYY”。保持这个简单的替换是我的 Facebook 应用程序配置中的一些值:
App ID: "XXX"
Display Name: "[blah blah blah]"
Namespace: "YYY"
App Domains: "YYY.com"
Sandbox Mode: "Enabled"
Canvas Page: "http://apps.facebook.com/YYY"
Canvas URL: "http://YYY.com/canvas/"
我不确定您可能还需要哪些其他详细信息来帮助我解决这个问题。列出的所有 URL 都有效。感谢您的帮助!
最佳答案
Notice that I had to change the js.src parameter near the bottom of the code from the example given in the tutorial.
为什么?您是否仅通过从文件系统调用浏览器中的页面来进行测试,而不是通过本地 Web 服务器通过 HTTP 进行测试?
如果是后者,那么您没有 Facebook 可以验证您的请求来源的“域”。设置本地网络服务器,通过它调用您的文档,然后重试,
关于facebook - FB.init(...) 错误 : "Given URL is not allowed by the Application configuration.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13618098/