Ruby-on-rails 如何将 localhost:3000 添加到 Facebook App 进行开发

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20910576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:11:17  来源:igfitidea点击:

How can I add localhost:3000 to Facebook App for development

ruby-on-railsfacebookruby-on-rails-4omniauth

提问by Don P

I am working on a Rails 4 app. On my laptop, development is done at localhost:3000. The actual domain of the site is roomidex.com.

我正在开发一个 Rails 4 应用程序。在我的笔记本电脑上,开发是在localhost:3000. 该网站的实际域名是roomidex.com.

How can I set up a Facebook app so it works on production and development?

如何设置 Facebook 应用,使其适用于生产和开发?

Here is the current configuration:

这是当前的配置:

App Domains: roomidex.com

Website With Facebook Login: 
Site URL: http://www.roomidex.com

When I try to do a Facebook login on localhost:3000, I get this not surprising error:

当我尝试在 localhost:3000 上登录 Facebook 时,我得到了这个并不奇怪的错误:

{
   "error": {
      "message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.",
      "type": "OAuthException",
      "code": 191
   }
}

回答by Don P

On the Facebook App page, click "edit App" then click "Advanced" in the left-hand navigation. Then for "Valid OAuth redirect URIs" add http://localhost:3000... or whatever you want the accepted redirect to be.

在 Facebook 应用页面上,单击“编辑应用”,然后单击左侧导航中的“高级”。然后为“有效的 OAuth 重定向 URI”添加http://localhost:3000... 或您希望接受的重定向的任何内容。

回答by Taylor714

You can create a test app that's connected to your main app. On the Dashboard or Settings page for your main app. scroll down and you'll see "Test Apps" in the menu that runs down the left side of the page. The test app will inherit settings from the main app, but it will permanently be in development mode, and it will have its own ID.

您可以创建一个连接到主应用程序的测试应用程序。在主应用程序的仪表板或设置页面上。向下滚动,您将在页面左侧的菜单中看到“测试应用程序”。测试应用程序将继承主应用程序的设置,但它将永久处于开发模式,并且将拥有自己的 ID。

More info on test apps here: https://developers.facebook.com/docs/apps/test-apps/

有关测试应用程序的更多信息,请访问:https: //developers.facebook.com/docs/apps/test-apps/

The protocol for setting up an app to work on localhost has changed. After you get your test app set up, this explains the steps for setting it up to work on localhost:

设置应用程序以在 localhost 上工作的协议已更改。在您设置好测试应用程序后,这解释了将其设置为在 localhost 上运行的步骤:

https://stackoverflow.com/a/24253054/2803458

https://stackoverflow.com/a/24253054/2803458

回答by Ivan Hanák

Your error is saying

你的错误是说

localhost URL is not allowed in the application

应用程序中不允许使用 localhost URL

I know, FB does not give a s**t about explaining, what do to in those moments, however, as far as I am concerned, I have found workaround.

我知道,FB 没有给出任何解释,在那些时刻该怎么做,但是,就我而言,我找到了解决方法。

Basically, you need to "whitelist" locahost url in your app

基本上,您需要在您的应用程序中将 locahost 网址“列入白名单”

Here is what you are going to do

这是你要做的

  1. Go to the app edit/summary page
  2. In the fourth field App Domains, you should already have roomidex.com, so add another address localhost
  3. The urls mentioned above are only valid, if each one of them is put into tabs, where you set, how you app integrates with Facebook(website with facebook login, App on facebook, Mobile web, …)
  4. I do this: I put my working URL, in your case roomidex.cominto Website with facebook login, and my test, localhostURL, either into App on facebookor Page tab
  1. 转到应用编辑/摘要页面
  2. 在第四个字段App Domains 中,您应该已经有了roomidex.com,所以添加另一个地址localhost
  3. 上面提到的网址只有在将每个网址都放入标签、您设置的位置、您的方式app integrates with Facebook(带有 facebook 登录的网站、facebook 上的应用程序、移动网络等)时才有效
  4. 我这样做:我把我的工作 URL,在你的情况下roomidex.com放入Website with facebook login,以及我的测试,本地主机URL,放入App on facebookPage tab

回答by Cadene

June 2015

2015 年 6 月

Go to My Apps > Settings > Basic

转到我的应用程序 > 设置 > 基本

App Domains

应用程序域

  • localhost
  • 本地主机

Site Web

网站

It didn't work with port 80 or without any port unfortunately.

不幸的是,它不适用于端口 80 或没有任何端口。

回答by user937284

Adding localhostto the Valid OAuth redirect URIsin the test app did notwork for me but adding 127.0.0.1did.

添加localhostValid OAuth redirect URIs测试应用程序对我不起作用,但添加127.0.0.1了。

回答by yellowreign

Facebook now requires "Valid OAuth redirect URIs" to be https.

Facebook 现在要求“有效的 OAuth 重定向 URI”为 https。

To use https locally (localhost:3000), I used [ngrok][1] which allows you to use https by providing a tunnel. To do this:

要在本地使用 https (localhost:3000),我使用了 [ngrok][1],它允许您通过提供隧道来使用 https。去做这个:

  1. I went to their website?and downloaded their program
  2. I extracted the file for the program
  3. In my console, I went into the directory where ngrok was extracted to and entered 'grok http 3000' on my Windows machine, others may use './grok http 3000'
  4. After entering that, ngrok provided a https address which I put into the?Valid OAuth Redirect URIs field in Facebook
  5. Then I started my server and was able to access it using that https address instead of localhost:3000
  1. 我去了他们的网站?并下载了他们的程序
  2. 我为程序提取了文件
  3. 在我的控制台中,我进入了 ngrok 被解压到的目录,并在我的 Windows 机器上输入了“grok http 3000”,其他人可能会使用“./grok http 3000”
  4. 输入后,ngrok 提供了一个 https 地址,我将其放入 Facebook 中的 Valid OAuth Redirect URIs 字段
  5. 然后我启动了我的服务器并且能够使用那个 https 地址而不是 localhost:3000 访问它

回答by phwd

Just create two applications.

只需创建两个应用程序。

One for testing and one for release. You cannot supply the app with separate URL configurations.

一种用于测试,一种用于发布。您不能为应用程序提供单独的 URL 配置。

回答by Yaniv Vova Alterman

Just edit your hosts file with your domain that pointing to localhost and it should work fine.

只需使用指向 localhost 的域编辑主机文件,它应该可以正常工作。