在开发 facebook 图网站时如何使用 localhost?

发布于 2024-09-10 18:06:51 字数 302 浏览 3 评论 0原文

我想使用 localhost 使用图形 API 来开发网站 facebook 应用程序。 我在 facebook 之前的 api 中使用 asp.net c# 工作,

我要写 http://localhost:4300/ 在应用程序设置的连接 URL 中。

现在它不起作用了。 它一直告诉我 应用程序名称发生错误。请稍后重试。

有人建议吗?

** 如果我上传网站,并使用网站 coonect url,它就可以工作。

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

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

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

anybody suggestions ?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

π浅易 2024-09-17 18:06:51

Facebook 并不关心您的服务器所在的实际 IP 地址 - 但它会检查引用页面的域名是否与您在 Facebook 注册的域名相同。在开发过程中使其正常工作的技巧是找到一种方法来使用您的域名,即使您只是在本地计算机上进行开发也是如此。

如果您可以完全控制 DNS 记录,则可以添加主机记录(例如 'test.yourdomain.com' ),该记录要么指向您的开发计算机的真实 IP 地址(如果它是静态 IP),要么只是指向 127.0.0.1。 0.1

如果您无权访问 DNS,那么在开发过程中解决此问题的最简单方法是简单地向计算机的主机文件(OSX 和大多数其他 UNIX 计算机上的“/etc/hosts”)添加一个指向域的条目您在 facebook 上注册到您的本地主机。 添加这样一行:

127.0.0.0 test.yourdomain.com

所以你需要在主机文件的末尾 这意味着,如果您现在在 Web 浏览器中输入 test.yourdomain.com,它将解析为您的本地计算机。

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

现在您应该能够在浏览器中使用“test.yourdomain.com”url(而不是“localhost”)在本地计算机上进行开发,并且一切都应该正常。

哦 - 还有一件事 - 如果您的开发服务器没有在端口 80 上运行,那么 facebook 重定向 uri 也需要有一个端口号,但它在匹配域 url 时包含此端口号(坦白说,我认为这是Facebook API)。这意味着,如果您的开发服务器(例如)在端口 8080 上运行,那么您需要将“:8080”添加到重定向 URI 中的主机名末尾,但如果您的生产服务器 在端口 80 上运行,那么您不应该在重定向 uri 中放入“:80”,否则只有当人们在用于查看您的 URL 中明确包含端口号时,它才会起作用。页面(不太可能在生产服务器中)。这一切在实践中意味着您只需要有一个条件,以便在生成 facebook 身份验证 URL 时仅包含端口号(如果端口号不是 80)。

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.

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

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

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.

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).

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

红焚 2024-09-17 18:06:51

将“localhost”添加到 Facebook 上应用程序的“应用程序域”设置中。另外,如果您正在执行诸如将“MyApp.test”重定向到本地服务器上的 127.0.0.1 之类的操作,您还可以将“MyApp.test”添加到“应用程序域”,这样它就可以工作。

我只是在寻找这个问题的解决方案后尝试了这个。这是一个非常简单的解决方案。

Add "localhost" to the "App Domain" setting of your app on Facebook. Also, if you are doing something like redirecting "MyApp.test" to 127.0.0.1 on your local server, you can also add "MyApp.test" to the "App Domain" and it will work.

I just tried this after looking for a solution to this problem. It is a very simple solution.

简单 2024-09-17 18:06:51

检查应用程序 Facebook 配置中的以下基本设置:

  • 命名空间已设置
  • 应用程序域包括“localhost”
  • Canvas URL 和安全 Canvas URL 的 URL 中均包含“localhost”域

如果您在使用应用程序时收到“应用程序名称”错误保存应用程序的配置设置 您确定应用程序的名称有效并且尚未使用?我们始终使用 localhost(带有 ASP.Net、IISExpress 和非常高的端口号)来处理四到五个不同的应用程序,这些应用程序在不同的计算机上有多个用户,并且不需要执行某些人在其答案中描述的任何额外步骤。

编辑:在重新阅读其他答案后,我猜一些开发人员正在与他们用于生产的同一个 Facebook 应用程序上进行开发,所以他们需要将他们的机器映射到生产域?我们不这样做,我们有两个“应用程序”。一种用于使用本地主机配置进行测试,另一种用于生产。我们有一个组件,可以在运行时确定它所处的环境,并构建所有必要的 URL,例如使用应用程序 ID 和应用程序密钥的 OAuth 重定向,因此我们始终运行相同的代码,只是部署在不同服务器上的不同配置。

Check the following Basic Settings in your app's Facebook configuration:

  • Namespace has been set
  • App Domain includes "localhost"
  • Canvas URL and Secure Canvas URL both have a domain of "localhost" in their URL

If you are getting an "application name" error when you save the app's configuration settings are you sure the name of the app is valid and not already taken? We use localhost (with ASP.Net, IISExpress, and very high port numbers) all the time with four or five different applications with multiple users on different machines and never need to do any of the extra steps some people have described in their answers.

EDIT: after re-reading other answers I guess some devs are developing on the same Facebook app as they use for production, so they need to map their machine to the production domain? We don't do that, we have two "apps". One is for testing with the localhost configuration and another for production. We have a component that determines at runtime which environment it's in and constructs all the necessary URLs such as OAuth redirects with App IDs and App Secrets so we're always running the same code, just different configuration deployed on different servers.

忘东忘西忘不掉你 2024-09-17 18:06:51

您确定该问题与您的 Web 服务器的 DNS 名称和/或端口有关吗?
如果是,您可以使用本地 IIS 而不是 webdev 服务器,配置一个网站 yourdomain.com 并向主机添加一个条目:
127.0.0.1 yourdomain.com

Are you sure that problem is related to DNS name and/or port of your web server?
If yes you can use your local IIS instead of webdev server, configure a website yourdomain.com and add an entry to the hosts saying
127.0.0.1 yourdomain.com

云胡 2024-09-17 18:06:51

如果我正确理解您要执行的操作并且应用程序设置位于 Facebook 网站上,则 Facebook 将无法使用“localhost”连接到您的计算机。获取您计算机的 IP 地址并将其输入到应用程序设置页面。

要查找您的 IP:http://whatismyipaddress.com/

If I understand correctly of what you're trying to do and the application settings are on Facebook's website, Facebook will not be able to connect to your computer with 'localhost'. Get the IP address of your computer and type that into the application settings page.

To find your IP: http://whatismyipaddress.com/

╰◇生如夏花灿烂 2024-09-17 18:06:51

您必须创建从开发服务器到本地主机计算机的 ssh 隧道。对开发服务器的每个请求都将由您的计算机处理并发回。

You have to create a ssh tunnel FROM develop server TO your localhost computer. Each request to dev server will be processed by your computer and send back.

小…楫夜泊 2024-09-17 18:06:51

您无法在 Facebook 设置上添加顶级域(仅供参考)

You cannot add top level domains on Facebook setting FYI

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文