我是Google API的新手,目前正在通过代码添加转发电子邮件地址。 以下是代码。
credentials = get_credentials(request.data['code'], request.data['state'])
service = build_gmail_service(credentials)
address = {'forwardingEmail': 'abcd1234@mydomain.com'}
result = service.users().settings().forwardingAddresses().create(userId='me', body=address).execute()
我能够使用上述代码构建谷歌服务,但在执行设置转发电子邮件地址的最后一行时出现以下错误。
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/gmail/v1/users/me/settings/forwardingAddresses?alt=json returned "Access restricted to service accounts that have been delegated domain-wide authority">
我已经搜索了一整天但无法解决它,请告诉我是否有其他人遇到过类似的问题并解决了它。
Gsuite 按域委派图片:
![enter image description here](https://istack.dev59.com/gxpUJ.webp)