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


当前回答

不要忘记在域名和ip后面加上路径。就我而言,我忘记了:

/ oauth2callback

其他回答

我在谷歌登录时也遇到了同样的问题。

我已经在谷歌开发人员控制台的谷歌凭据面板中正确输入了我的回调 这是我的重定向网址:

https://www.example.com/signin-google

https://www.example.com/signin-google/

https://www.example.com/oauth2callback

https://www.example.com/oauth2callback/

一切似乎都很好,对吧?但它仍然没有工作,直到我添加了一个更神奇的Url,我添加了sign -google Url(这是默认的谷歌回调)没有www和问题解决。

考虑到这一点(取决于你的域名),你可能需要或不需要同时添加www url

2015年7月15日-上周在登录时使用这个脚本工作的登录

<script src="https://apis.google.com/js/platform.js" async defer></script>

停止工作并开始导致Error 400 with Error: redirect_uri_mismatch

然后在DETAILS部分:redirect_uri=storagerelay://…

我把它改成:

<script src="https://apis.google.com/js/client:platform.js?onload=startApp"></script>

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

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

就我而言,我补充道

https://websitename.com/sociallogin/social/callback/?hauth.done=Google

在授权重定向uri部分,它为我工作