9
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.我在做本地Facebook应用程序开发时做了什么错误?

我做了查看源代码,看看以下内容:

<!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> 

回答

11

您应该使用当您想要将您的Facebook应用程序连接到您的本地环境时使用一些别名域。

尝试以下操作:

  1. 转到您的etc/hosts(或%systemroot%/system32/drivers/etc/hosts)文件,并添加下面一行:通过简单地利用

    127.0.0.1 foo.local # alias domain

  2. 转到App > Settings和注册应用程序foo.local作为应用程序域。

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

  4. 完成。

于2016年1月16日编辑:

Facebook已经改变了自己的UI,请按照下列步骤进行它的工作原理。

  1. 转到App > Settings > Basic (tab)
  2. 点击Add Platform,选择 “网站”,输入您的别名域。
  3. 将您的域添加到App Domain部分。
  4. 完成。
+0

由于SO watchdongs不会让我编辑答案,所以我会发布正确的部分作为评论:问题是,在某个时间点,我已将Advanced OAuth重定向URI设置为高级设置不同的,这是压倒所有其他设置。清空该字段解决了问题,但是当然,正确的解决方法是将该字段设置为我想要接收访问令牌的特定URL。 – necromancer 2013-05-03 02:50:39

+0

梦幻般的答案! – user123 2013-07-18 10:21:13

+0

除此之外,如果您使用的是自定义端口,例如127:0.0.1:8080,对我来说,只有当我在Facebook的应用程序短划线中添加端口时才起作用。所以在/ etc/hosts 127.0.0.1中,但在FB:127.0.0.1:8080中 – willdanceforfun 2015-11-21 04:32:12