我在 localhost Facebook 应用程序开发中做错了什么? [英] What am I doing wrong in localhost Facebook app development?
问题描述
App Domains: localhost
Website with Facebook login: http://localhost/auth
我转到 http://localhost/auth/
并在我的 Chrome 开发者控制台中看到错误:应用程序配置不允许给定 URL.:一个或多个应用程序的设置不允许给定的 URL.它必须与网站 URL 或画布 URL 匹配,或者域必须是应用域之一的子域.
I go to http://localhost/auth/
and in my Chrome developer console I see the error: 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.
我做了一个查看源代码来查看以下内容:
I do a view-source to see the following:
<!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
并查看源代码以查看单行:
I go to http://localhost/auth/channel.html
and view source to see the single line:
<script src="//connect.facebook.net/en_US/all.js"></script>
推荐答案
当您想将 Facebook 应用程序与本地环境连接时,您应该使用一些别名域.
You should use some alias domain when you want to connect your Facebook application with your local environment.
尝试以下操作:
转到您的
etc/hosts
(或%systemroot%/system32/drivers/etc/hosts
)文件并添加以下行:
Go to your
etc/hosts
(or%systemroot%/system32/drivers/etc/hosts
) file and add the following line:
127.0.0.1 foo.local #别名域
转到应用程序>设置
并通过简单地使用 foo.local
作为应用程序域来注册您的应用程序.
Go to App > Settings
and register your application by simply using foo.local
as app domain.
添加您的站点 URL(例如 http://foo.local/project/ )
Add your Site URL (e.g. http://foo.local/project/ )
完成.
2016 年 1 月 16 日
Facebook 已更改其用户界面,请按照以下步骤操作.
Facebook has changed their UI, follow these steps to make it works.
- 转到
应用程序>设置 >基本(选项卡)
- 点击
Add Platform
,选择网站"并输入您的别名域. - 在
App Domain
部分添加您的域. - 完成.
- Go to
App > Settings > Basic (tab)
- Click on
Add Platform
, select "Website" and enter your alias domain. - Add your domain in
App Domain
section. - Done.
这篇关于我在 localhost Facebook 应用程序开发中做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!