在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。


当前回答

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

只使用:

http://localhost/oauth2callback

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

其他回答

I had this problem using Meteor and Ngrok, while trying to login with Google. I put the Ngrok URL in the Google Developer Console as redirect URLs, and went to the Ngrok URL page. The thing was that I didn't use Meteor's ROOT_URL when executing the app, so any redirect would go to localhost:3000 insted of the Ngrok URL. Just fixed it by adding the Ngrok URL as ROOT_URL on Meteor's configuration or by exporting it before executing the app on the terminal like: export ROOT_URL=https://my_ngrok_url

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

我的观点是: 如果使用Google_Client库,不要忘记在更新重定向URI之后更新服务器上的JSON文件。

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分钟,然后尝试再次登录

以下是Error: redirect_uri_mismatch问题发生的原因:

重定向URL字段空白在您的谷歌项目。 重定向URL与您的网站不匹配 重要!它将只与工作域,如example.com, book.com等(不与本地主机或AWS LB URL工作)

建议使用域URL