Python gmail api-域范围授权
我正在尝试获取特定域的所有用户的电子邮件。我能够收到创建服务帐户(管理员帐户)的用户的电子邮件,但在收到该域其他用户的电子邮件时,我面临HttpError 403“委派被拒绝xxx@example.com“ 我执行了以下步骤:Python gmail api-域范围授权,python,gmail-api,google-api-python-client,service-accounts,google-gsuite,Python,Gmail Api,Google Api Python Client,Service Accounts,Google Gsuite,我正在尝试获取特定域的所有用户的电子邮件。我能够收到创建服务帐户(管理员帐户)的用户的电子邮件,但在收到该域其他用户的电子邮件时,我面临HttpError 403“委派被拒绝xxx@example.com“ 我执行了以下步骤: 创建了一个项目,获取了一个credentials.json文件,并使用该文件创建了一个token.json文件来验证请求 创建了服务帐户并启用了域范围的委派 已从该服务帐户收集客户端id 然后使用此指南链接将整个域的权限委托给该服务帐户 下面是我请求获取其他用户的电子
- 创建了一个项目,获取了一个credentials.json文件,并使用该文件创建了一个token.json文件来验证请求
- 创建了服务帐户并启用了域范围的委派
- 已从该服务帐户收集客户端id
- 然后使用此指南链接将整个域的权限委托给该服务帐户
谢谢 您确定这是可能的吗?您是否检查了凭据是否能够模拟用户?检查:
from googleapiclient.discovery import build
from oauth2client import file
from httplib2 import Http
TOKEN_FILEPATH = "/path-to-token-file/"
def get_auth():
store = file.Storage(TOKEN_FILEPATH)
creds = store.get()
service = build('gmail', 'v1', http=creds.authorize(Http()))
return service
def get_emails():
user = 'xxx@example.com'
service = get_auth()
response = service.users().messages().list(userId=user).execute()