我正在使用python中的Gmail API,通过以下方式获取请求
gmail_auth = GmailUserSocialAuth.objects.filter(uid='...')[0]
response = gmail_auth.request('get', '...')
data = response.json()
response - gmail_auth.request('get', '/%s' % data['messages'][0]['id']
message = response.json()
当我打印出消息时,我会得到包含所有字段等的大型大对象。有一条消息,我得到了这个回复:
{
... # a lot of fields
u'sizeEstimate': 10100,
'html_body': '',
'decoded_body': '',
u'snippet': u'Hi —, <content of email>. On Jun 30, 2016..., Ofek Gila <...> wrote: <content of previous email in thread>.',
}
无论如何,问题是我知道电子邮件是因为它出现在代码段中而写的,但它并没有显示在邮件对象的任何其他位置。
知道会发生什么事吗?
提前致谢!
答案 0 :(得分:1)
尝试使用Python sample code中所述的 获取 方法。 这是一个片段:
def GetMimeMessage(service, user_id, msg_id):
"""Get a Message and use it to create a MIME 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.
msg_id: The ID of the Message required.
Returns:
A MIME Message, consisting of data from Message.
"""
try:
message = service.users().messages().get(userId=user_id, id=msg_id,
format='raw').execute()
print 'Message snippet: %s' % message['snippet']
msg_str = base64.urlsafe_b64decode(message['raw'].encode('ASCII'))
mime_msg = email.message_from_string(msg_str)
return mime_msg
except errors.HttpError, error:
print 'An error occurred: %s' % error