Gmail API OAuth2错误:redirect_uri_mismatch [英] Gmail API OAuth2 Error: redirect_uri_mismatch

查看:109
本文介绍了Gmail API OAuth2错误:redirect_uri_mismatch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了此Gmail API Python快速入门教程: https://developers.google.com/gmail/api/quickstart/python

I followed this Gmail API Python Quickstart tutorial: https://developers.google.com/gmail/api/quickstart/python

我已按照指示在API控制台中配置了我的OAuth客户端ID(请参见下面的第一张图片).但是,启动脚本会打开浏览器会话,并导致下面的400错误.

I configured my OAuth client ID in the API console as instructed (see the first image below). However, launching the script opens a browser session that results in the 400 error below.

重定向URL与在API控制台中注册的URL匹配.

The redirect URL matches what is registered in the API console.

但是,快速入门脚本会打开以下URL: https://accounts.google.com/o/oauth2 ...& redirect_uri = http%3A%2F%2Flocalhost%3A8080%2F ...

HOWEVER, the quickstart script opens the following URL: https://accounts.google.com/o/oauth2... &redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F ...

手动将重定向URI更改为 http://localhost:8080 部分修复了我继续进行授权请求时遇到的问题,但响应无法返回到命令提示符.

Manually changing redirect URI to http://localhost:8080 partially fixes the problem as I proceed to the authorization request, but then the response can't get returned to the command prompt.

如何强制快速入门程序生成一个将重定向URI保留为 http://localhost:8080的URL ?

How can I force the quickstart program to produce a URL that leaves the redirect URI as http://localhost:8080?

推荐答案

您收到的错误原因是

The cause of the error you're getting is that the Python Quickstart says:

d .选择凭据"选项卡,单击创建凭据"按钮,然后选择OAuth客户端ID.

d. Select the Credentials tab, click the Create credentials button and select OAuth client ID.

e .选择应用程序类型 Other ,输入名称"Gmail API快速入门",然后单击创建"按钮.

e. Select the application type Other, enter the name "Gmail API Quickstart", and click the Create button.

但是,在查看您的工作时,您使用的是 Web应用程序,而不是其他.

However, looking at what you're doing, you are using Web Application instead of Other.

当我将 Other 用作client_secret.json时,我没有遇到此问题.

When I used the Other as client_secret.json, I didn't encounter this problem.

结果:

身份验证流程已完成.

The authentication flow has completed.

无需黑客/变通方法.只需按照说明进行操作即可:)

No hacks/workaround needed. Just follow instructions :)

这篇关于Gmail API OAuth2错误:redirect_uri_mismatch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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