访问 Google API 时的 OAuth 2.0 示例错误
通过开源项目 google-api-ruby-client,我我正在尝试运行 OAuth 2.0 示例 calendar.rb,它将访问 Google Calendar API。 我已经在 Google API 控制台中创建了客户端 ID,并在 ruby 脚本中填写了客户端 ID 和密钥。
但是,在我运行 ruby 脚本
ruby calendar.rb
然后打开 http://localhost:4567 后,浏览器从 Google 返回错误信息我:
Error: redirect_uri_mismatch
The redirect URI in the request: http://localhost:4567/oauth2callback did not match a registered redirect URI
我查了Google API控制台的信息:
Redirect URIs: https://localhost/oauth2callback
JavaScript origins: https://localhost
是什么问题,如何解决?提前致谢。
With the open source project google-api-ruby-client, I'm trying to run the OAuth 2.0 sample calendar.rb, which will access Google Calendar API.
I've created client ID in Google API console, and fill the client ID and the secret in the ruby script.
However, after I run the ruby script
ruby calendar.rb
and then open http://localhost:4567, the browser return error information from Google to me:
Error: redirect_uri_mismatch
The redirect URI in the request: http://localhost:4567/oauth2callback did not match a registered redirect URI
I checked the information in the Google API console:
Redirect URIs: https://localhost/oauth2callback
JavaScript origins: https://localhost
What's the problem and how to solve it? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
重定向 URI 必须完全匹配。你不能省略任何东西。您已删除端口号。但是不匹配尾部斜杠或其他任何东西都会导致此错误。它必须是精确的、逐个字符的匹配。
这两个值应为:
重定向 URI:
https://localhost:4567/oauth2callback
JavaScript 来源:
https://localhost:4567
The redirect URI has to match exactly. You can't omit anything. You've dropped the port number. But mismatching a trailing slash or really anything else will cause this error. It has to be an exact, character-for-character match.
The two values should be:
Redirect URIs:
https://localhost:4567/oauth2callback
JavaScript origins:
https://localhost:4567
我没有端口号,但运行得很好。
但是,重定向 URI 是: http://localhost/oauth2callback
我昨晚运行了这个示例。
I didn't have the port numbers and it worked fine.
However, the Redirect URI was: http://localhost/oauth2callback
I had this example working last night.
我遇到了同样的问题。一切都匹配,URL 正确,同意页面已填写,但我必须生成新的客户端 ID 3 次。第三次就开始起作用了。我不知道原因。我没有更改任何配置或代码,它只是开始使用第三个客户端 ID 和客户端密钥。
I faced the same problem. Everything was matching, URL was correct, consent page was filled, but I had to generate a new Client ID three times. It started working just on the third time. I don't know the reason. I didn't change anything in configuration or code, it just started working with the third Client ID and Client Secret.