在https://code.google.com/apis/console网站上,我已经注册了我的应用程序,设置生成的客户端ID:和客户端秘密到我的应用程序,并尝试登录谷歌。 不幸的是,我收到了错误信息:

Error: redirect_uri_mismatch
The redirect URI in the request: http://127.0.0.1:3000/auth/google_oauth2/callback did not match a registered redirect URI

scope=https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email
response_type=code
redirect_uri=http://127.0.0.1:3000/auth/google_oauth2/callback
access_type=offline
approval_prompt=force
client_id=generated_id

这条信息是什么意思,我该如何修复它? 我使用宝石omniauth-google-oauth2。


当前回答

我需要在api和服务下创建一个新的客户端ID ->凭据->创建凭据-> OAuth ->其他

然后下载并使用client_secret。Json和我的命令行程序上传到我的YouTube帐户。我试图使用Web应用程序OAuth客户端ID,这给了我浏览器中的重定向URI错误。

其他回答

Let me complete @Bazyl's answer: in the message I received, they mentioned the URI "http://localhost:8080/" (which of course, seems an internal google configuration). I changed the authorized URI for that one, "http://localhost:8080/" , and the message didn't appear anymore... And the video got uploaded... The APIS documentation is VERY lame... Every time I have something working with google apis, I simply feel "lucky", but there's a lack of good documentation about it.... :( Yes, I got it working, but I don't yet understand neither why it failed, nor why it worked... There was only ONE place to confirm the URI in the web, and it got copied in the client_secrets.json... I don't get if there's a THIRD place where one should write the same URI... I find nor only the documentation but also the GUI design of Google's api quite lame...

在我的情况下,它是www和非www URL。实际网站有www URL和谷歌开发控制台授权重定向uri有非www URL。因此,重定向URI存在不匹配。我通过将谷歌开发人员控制台中的授权重定向uri更新为www URL解决了这个问题。

其他常见的URI不匹配有:

在授权重定向uri中使用http://和https://作为实际URL,反之亦然 在授权重定向uri中使用尾随斜杠(http://example.com/),而不使用尾随斜杠(http://example.com)作为实际URL,反之亦然

下面是谷歌开发人员控制台的逐步截图,这样对于那些很难找到开发人员控制台页面来更新重定向uri的人是有帮助的。

访问https://console.developers.google.com 选择您的项目

点击菜单图标

单击API管理器菜单

点击凭证菜单。在OAuth 2.0客户端id下,您将找到您的客户端名称。在我的例子中,它是Web客户机1。点击它,一个弹出窗口将出现,你可以编辑授权Javascript源和授权重定向uri。

注意:默认情况下,授权URI包括所有本地主机链接,任何活动版本都需要包括完整路径,而不仅仅是域,例如https://example.com/path/to/oauth/url

下面是谷歌关于创建项目和客户端ID的文章。

1.您将看到类似这样的错误

2.然后单击请求详细信息

在此之后,您必须复制该url并将其添加到https://console.cloud.google.com/

访问https://console.cloud.google.com/

点击菜单-> API和服务->凭证

你会看到一个这样的仪表板,点击编辑OAuth客户端 现在在授权Javascript起源和授权重定向url 添加显示错误的url,称为redirect_uri_mismatch,即这里 http://algorithammer.herokuapp.com,所以我在这两个地方都加了 授权Javascript源和授权重定向url 点击保存,等待5分钟,然后尝试再次登录

重定向URI(返回响应的地方)必须在api控制台中注册,错误指示您没有这样做,或者没有正确地这样做。

转到项目的控制台,在API Access下查看。您应该在那里看到您的客户端ID和客户端秘密,以及一个重定向uri列表。如果您想要的URI没有列出,单击编辑设置并将URI添加到列表中。

编辑:(来自下面评价很高的评论)请注意,更新谷歌api控制台和当前的更改可能需要一些时间。通常只有几分钟,但有时似乎更长。

更新—>适用于Android应用程序

只使用:

http://localhost/oauth2callback

如果你处理自己的逻辑没有重定向链接的web应用程序