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


当前回答

对我来说,这是因为在“授权重定向uri”列表中,我错误地把https://developers.google.com/oauthplayground/而不是https://developers.google.com/oauthplayground(没有/在最后)。

其他回答

The trick is to input the right redirect url at the point of creating the ID. I found that updating the redirect url once the ID has been created via an 'Edit' just doesn't get the job done. What also worked for me is duplicating the entire 'vendor' folder and copying it to the same location where the 'oauth' file is (just until you successfully generate the token and then you can delete the duplicate 'vendor' folder). This is because trying to point to the vendor folder via '../vendor/autoload' didn't work for me.

因此,删除您现有的麻烦客户端OAuth ID,并尝试这种方法,它将工作。

重要补充:我发现在跨客户端服务器认证流程中,当你从Web SDK接收到serverAuthCode时,你应该使用“postmessage”,当你从Android或iOS SDK接收到serverAuthCode时,将redirect_uri设置为空。

任何人努力寻找在新的控制台设置重定向url: api和认证->凭据-> OAuth 2.0客户端id ->单击链接找到所有的重定向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...

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