我可以在Gmail应用中打开我的电子邮件主题吗?如果我有id或threadId?

时间:2015-09-21 09:16:27

标签: android gmail-api

我在我的Android应用程序中使用gmail API,我能够获取id和threadId.So有什么方法可以使用这些ID填充gmail。

2 个答案:

答案 0 :(得分:1)

一旦您有messageId代表您想要的消息,您就可以使用Users.messages: get - 操作来获取电子邮件。您可以手动执行请求

GET https://www.googleapis.com/gmail/v1/users/me/messages/<MESSAGE_ID>

或借助图书馆:

Message message = service.users().messages().get('me', messageId).execute();

如果您想获取帖子中的所有邮件it is just as easy to do that also

查看代码示例并在我提供的链接中探索API。

答案 1 :(得分:1)

您可以通过以下方式获取原始消息这是在python中但在Java中它将是类似的。我希望我回答你在寻找什么。

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']
        print 'keys ', message.keys()
        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

for i in range(0,len(th['messages'])):

    print 'snippent --- ', th['messages'][i]['snippet']
    id = th['messages'][i]['id']
    print 'id---', id
    msg = GetMimeMessage(service, 'me', id )
    pay = msg.get_payload()
    pay1 = pay[0]
    print 'msg --- ', pay1.get_payload()