访问Google API时出现OAuth 2.0示例错误 [英] OAuth 2.0 sample error when accessing Google API

查看:160
本文介绍了访问Google API时出现OAuth 2.0示例错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用开源项目 google-api-ruby-client ,我试图运行OAuth 2.0示例calendar.rb,它将访问Google Calendar API。
我在Google API控制台中创建了客户端ID,并将客户端ID和秘密填充到了ruby脚本中。



但是,在运行ruby脚本

  ruby​​ calendar.rb 

,然后打开 http:// localhost:4567 ,浏览器将错误信息从Google返回到我:

 错误:redirect_uri_mismatch 
请求中的重定向URI:http:// localhost:4567 / oauth2callback确实不匹配已注册的重定向URI

我检查了Google API控制台中的信息:

 重定向URI:https:// localhost / oauth2callback 
JavaScript起源:https:// localhost

有什么问题以及如何解决它?提前致谢。

解决方案

重定向URI必须完全匹配。你不能忽略任何东西。你已经放弃了端口号码。但是,如果不匹配斜线或其他任何内容,都会导致此错误。它必须是一个精确的,字符匹配的字符。



这两个值应该是:

重定向URI: https:// localhost:4567 / oauth2callback



JavaScript起源: https :// localhost:4567


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.

解决方案

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

这篇关于访问Google API时出现OAuth 2.0示例错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆