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