在开源项目 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
问题是什么以及如何解决?提前致谢。
最佳答案
重定向 URI 必须完全匹配。你不能遗漏任何东西。您已经删除了端口号。但是不匹配尾部斜杠或其他任何东西都会导致此错误。它必须是一个字符对字符的精确匹配。
这两个值应该是:
重定向 URI:https://localhost:4567/oauth2callback
JavaScript 来源:https://localhost:4567
关于ruby - 访问 Google API 时的 OAuth 2.0 示例错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9290182/