Gmail Api返回未经授权的客户端或请求范围 [英] Gmail Api return Unauthorized client or scope in request

查看:211
本文介绍了Gmail Api返回未经授权的客户端或请求范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力完成这项工作,但完成了一半的工作.

I have struggled to make this work but did half the job.

实际上,我只能从Gmail API中读取邮件,如果尝试使用gmail.modify范围,则会收到错误消息:

Actually I can only read messages from Gmail API, If I try to use the gmail.modify Scope I get an error:

HttpAccessTokenRefreshError:未经授权的客户端:请求中未经授权的客户端或范围.

这是我的代码:

# init gmail api
credentials_path = os.path.join(settings.PROJECT_DIR, 'settings/gmail_credential.json')
scopes = ['https://www.googleapis.com/auth/gmail.readonly',
          'https://www.googleapis.com/auth/gmail.modify']
credentials = ServiceAccountCredentials.from_json_keyfile_name(credentials_path, scopes=scopes)
delegated_credentials = credentials.create_delegated('my_account@gmail.com')
http_auth = delegated_credentials.authorize(Http())
gmail = build('gmail', 'v1', http=http_auth)

在我的服务帐户中:

  • 我已将所有可能的规则设置为我的服务帐户"...... iam.gserviceaccount.com"
  • 我激活了DWD:DwD:启用了Google Apps域范围委派.

我在某处阅读过我需要一个Google工作帐户才能授予我的服务帐户使用gmail.Mod的权限.请在my_account @ gmail电子邮件帐户上进行修改.似乎很难修改电子邮件中的消息.

I have read somewhere that I need a google work account to give permission to my service account to use gmail.Modify on my my_account@gmail email account. Seems very hard way to just modify a message in an email.

我不知道下一步该怎么做.

I don't know what to do next.

推荐答案

基于此文档,则在设置API作用域时,需要使用开发人员控制台"中的客户端ID作为管理API客户端访问权限"中的客户端名称.您的个人帐户@ gmail.com不能正常使用Google API.您应该以you@your_organisation_domain的格式在Google中拥有组织域帐户.

Based from this documentation, you need to use the client ID from your "Developers Console" as the Client Name in the "Manage API client access" when you're setting your API scopes. Google API does not work as expected with your personal account @gmail.com. You should have organization domain account in Google in format you@your_organisation_domain.

检查这些线程:

  • Google API Python unauthorized_client: Unauthorized client or scope in request
  • Google API OAuth2, Service Account, "error" : "invalid_grant"

这篇关于Gmail Api返回未经授权的客户端或请求范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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