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


当前回答

我也得到这个错误error -400: redirect_uri_mismatch

这不是一个服务器或客户端错误,但你只需要检查你没有在结尾添加/(正斜杠)就可以了

重定向URL列表❌:

https://developers.google.com/oauthplayground/

这样做只✅:

https://developers.google.com/oauthplayground

其他回答

如果你使用谷歌+ javascript按钮,那么你必须使用postmessage而不是实际的URI。我花了几乎一整天的时间才弄清楚,因为谷歌的文档出于某种原因没有清楚地说明它。

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

我有前端应用程序和后端api。

从我的后端服务器,我通过点击谷歌api进行测试,并面临这个错误。在我的整个时间里,我想知道为什么我需要给redirect_uri,因为这只是后端,对于前端它是有意义的。

我所做的是给不同的redirect_uri(虽然有效)从服务器(假设这只是占位符,它只需要注册到谷歌),但我的前端url创建令牌代码是不同的。因此,当我在服务器端测试中传递这段代码时(redirect-uri是不同的),我遇到了这个错误。

所以不要犯这个错误。确保您的frontend redirect_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...

我的问题是,我在地址栏中有http://localhost:3000/,在console.developers.google.com中有http://127.0.0.1:3000/