在开发facebook图表网站时,如何使用localhost? [英] how can i use localhost while developing facebook graph website?

查看:133
本文介绍了在开发facebook图表网站时,如何使用localhost?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用本地主机开发网站facebook应用程序使用图形API。
i工作在asp.net c#

i want to use localhost for developing website facebook application using the graph api. i working in asp.net c#

在以前的api的Facebook我是abe写
http:// localhost:4300 / 在应用程序设置的连接url。

in the previous api of facebook i was abe to write the http://localhost:4300/ in the connect url at the application settings.

现在它dosent工作。
它不断告诉我
应用程序名称发生错误。请稍后再试。

now it dosent work. it keeps telling me An error occurred with application name. Please try again later.

有人建议吗?

**如果我上传网站,并使用网站coonect url,它正在工作。

** if i upload the website, and use the website coonect url, it is working.

推荐答案

Facebook不在乎您的服务器的实际IP地址,但它会检查引用页面的域名是否与您在Facebook上注册的域名相同。在开发过程中让它工作的窍门是找到一种方法来使用您的域名,即使您刚刚在本地计算机上进行开发。

Facebook doesn't care what actual IP address your server is located at - but it will check that the domain name of the referring page is the same as the domain you registered with facebook. The trick to getting it to work during development is to find a way to use your domain name even when you're just working on your local machine for development.

如果您完全控制您的DNS记录,您可以添加一个主机记录(例如test.yourdomain.com),它们指向您的开发机器的真实IP地址(如果它是静态ip),或简单到127.0.0.1

If you have full control of your DNS records you could add a host record (eg 'test.yourdomain.com' ) which either points at the real IP address of your development machine (if it's a static ip), or simply to 127.0.0.1

如果您无法访问DNS,那么在开发过程中最简单的方法就是简单地在计算机的主机文件中添加一个条目('/ etc /将OSX和大多数其他unix机器上的主机指向您在Facebook上注册的域到本地主机。所以你可以添加一行:

If you don't have access to your DNS then the easiest way to get around this during development is to simply add an entry to your computer's hosts file ('/etc/hosts' on OSX and most other unix machines) pointing the domain you registered at facebook to your local host machine. so you'd add a line like this :

127.0.0.0 test.yourdomain.com

到您的主机文件的末尾。这意味着如果您现在在您的网络浏览器中输入test.yourdomain.com,它将会解析到本地计算机。

to the end of your hosts file. That means that if you now enter test.yourdomain.com in your web browser it will resolve to your local machine.

现在 - 在您的网站部分Facebook中的应用程序设置确保已将您的域名添加到设置的站点域部分 - 这将意味着Facebook将接受来自域的任何子域的请求 - 换句话说,它将接受来自www 你的生产服务器和test.yourdomain.com(你的本地开发机器)。

Now - in the "web site" section of your application setup in Facebook make sure you have added your domain name to the "site domain" section of the setting - this will mean that facebook will accept requests coming from any subdomain of your domain - in other words it will accept requests from both "www.yourdomain.com" (your production server) and "test.yourdomain.com" (your local development machine).

现在你应该可以开发你的本地机器在浏览器中使用test.yourdomain.comurl,而不是localhost,一切都应该可以工作。

Now you should just be able to develop on your local machine using the "test.yourdomain.com" url in your browser rather than 'localhost' and everything should work.

OH - 还有一件事 - facebook redirect uri如果您的开发服务器未在端口80上运行,则还需要有一个端口号,但是当匹配域URL时它包含此端口号(坦白说,我认为这是Facebook API中的错误)。这意味着如果您的开发服务器(例如)在8080端口上运行,则需要在重定向URI中的主机名末尾添加:8080,但如果您的产品服务器 >在80端口上运行,那么你不应该将:80放在重定向uri中,否则只有当用户明确地将端口号包含在他们用来查看你的页面(生产服务器中不太可能)。这在实践中意味着你只需要一个条件,以便在生成Facebook身份验证URL时,只有端口号不包含端口号80。

OH - one more thing - the facebook redirect uri will also need to have a port number if your development server isn't running on port 80, but it includes this port number when matching the domain url (frankly i consider this a bug in the facebook APIs). This means that if your development server is (for instance) running on port 8080 then you'll need to add ':8080' to the end of the hostname in the redirect URI, but if your productions server is running on port 80 then you shouldn't put ":80" in the redirect uri because otherwise it'll only work when people have explicitly included the port number in the URL they used to look at your page (unlikely in a production server). What this all means in practice is that you just have to have a conditional so that when generating the facebook authentication URL you only include the port number if it's not port 80.

这篇关于在开发facebook图表网站时,如何使用localhost?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆