我正在努力解决Google Gmail API(Python(的奇怪问题。我正在尝试发送消息,凭据看起来正确(如果我允许应用程序管理电子邮件等,我被重定向到网站接受。(
(范围:'https://mail.google.com/'
代码:
import httplib2
from apiclient import discovery
def SendMessage(user_id, message):
"""Send an email message.
Args:
service: Authorized Gmail API service instance.
user_id: User's email address. The special value "me"
can be used to indicate the authenticated user.
message: Message to be sent.
Returns:
Sent Message.
"""
from GoogleCredentialsMail import get_credentials
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.build('admin', 'directory_v1', http=http)
message = (service.users().messages().send(userId=user_id,
body=message).execute())
print('Message Id: %s' % message['id'])
return(message)
但是我有一个错误:
AttributeError: 'Resource' object has no attribute 'messages'
有什么建议吗?
链接到API:https://developers.google.com/gmail/api/guides/sending
当我与管理员目录(在Google API中移动的构建机器人(一起工作时,我习惯了:
service = discovery.build('admin', 'directory_v1', http=http)
多亏了Igle,我开始从开始并发现棘手的错误重新思考。我现在开始工作,看起来:
service = discovery.build('gmail', 'v1', http=http)