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


当前回答

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

其他回答

在我的例子中,我的证书应用类型是“其他”。所以我无法在凭证页中找到授权重定向uri。它似乎出现在应用程序类型:“Web应用程序”。但是您可以单击Download JSON按钮来获取client_secret。json文件。

打开json文件,你可以找到这样的参数:"redirect_uri ":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]。我选择使用http://localhost,它很适合我。

确保检查协议“http://”或“https://”,因为谷歌也检查协议。 最好将两个URL都添加到列表中。

重定向url区分大小写。

在我的例子中,我添加了两个: http://localhost:5023/AuthCallback/IndexAsync http://localhost:5023/authcallback/indexasync

在我的情况下,我必须检查客户端ID类型的web应用程序/已安装的应用程序。

已安装的应用程序:http://localhost[重定向uri] 在这种情况下,localhost就可以工作了

web应用程序:您需要有效的域名[重定向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...