我在本地主机Facebook应用开发中做错了什么?


App Domains: localhost
Website with Facebook login: http://localhost/auth

我去http://localhost/auth/,在我的Chrome开发者控制台,我看到错误:Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.

我做了一个查看源来查看以下内容:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div id="fb-root"></div>
<script>
  // Additional JS functions here
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'myappidremovedfromstackoverflowquestion', // App ID
      channelUrl : '//localhost/auth/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
    });
    // Additional init code here
  };
  // 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 = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>
<p>hello</p>
</body>
</html>

我转到http://localhost/auth/channel.html并查看源代码,看到单行:

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

当你想要将你的Facebook应用程序与本地环境连接起来时,你应该使用一些别名域。

尝试以下操作:

  1. 转到etc/hosts(或%systemroot%/system32/drivers/etc/hosts)文件并添加以下行:

    127.0.0.1 foo.local # alias domain

  2. 转到App > Settings并通过简单地使用foo.local作为应用程序域来注册您的应用程序。

  3. 添加您的网站URL(例如http://foo.local/project/)

编辑于2016年1月16日:

Facebook已经改变了他们的UI,遵循以下步骤使其工作。

  1. 转到App > Settings > Basic (tab)
  2. 点击Add Platform,选择"网站"并输入别名域名。
  3. App Domain部分添加您的域名。

相关内容

最新更新