我在localhost Facebook应用程序开发中做错了什么?

nec*_*cer 9 facebook oauth-2.0 facebook-javascript-sdk facebook-oauth

App Domains: localhost
Website with Facebook login: http://localhost/auth
Run Code Online (Sandbox Code Playgroud)

我转到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.

我做一个view-source看到以下内容:

<!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>
Run Code Online (Sandbox Code Playgroud)

我去http://localhost/auth/channel.html查看源代码以查看单行:

<script src="//connect.facebook.net/en_US/all.js"></script>
Run Code Online (Sandbox Code Playgroud)

kav*_*kav 11

如果要将Facebook应用程序与本地环境连接,则应使用某些别名域.

请尝试以下方法:

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

    127.0.0.1 foo.local # alias domain

  2. App > Settings只需使用foo.localapp域即可转到并注册您的应用程序.

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

  4. 完成.

2016年1月16日编辑:

Facebook已经改变了他们的用户界面,按照这些步骤使其有效.

  1. App > Settings > Basic (tab)
  2. 单击Add Platform,选择"网站"并输入您的别名域.
  3. App Domain部分中添加您的域名.
  4. 完成.