如何从Gmail API获取上次收到的电子邮件或最新的收件箱邮件?

时间:2016-01-04 09:33:51

标签: android email gmail gmail-api

I have already login through GoogleApiClient in my application.  
I am also able to List of email matching query using google api sample.

users.messages.list     通过此链接,我收到带有查询文本(搜索词)的用户电子邮件。

1.我需要使用gmail api收到上一封电子邮件。

1 个答案:

答案 0 :(得分:2)

Listing只是问题的一半:

请求

maxResults = 1
q = -from:me

GET https://www.googleapis.com/gmail/v1/users/me/messages?maxResults=1&q=-from%3Ame&access_token={YOUR_API_KEY}

<强>响应

{
 "messages": [
  {
   "id": "1520a62ee385565e",
   "threadId": "1520a62ee385565e"
  }
 ],
 "nextPageToken": "17704551804303833190",
 "resultSizeEstimate": 1
}

之后,您需要Get特定的电子邮件:

请求

GET https://www.googleapis.com/gmail/v1/users/me/messages/1520a62ee385565e?access_token={YOUR_API_KEY}

<强>响应

{
 "id": "1520a62ee385565e",
 "threadId": "1520a62ee385565e",
 "labelIds": [
  "INBOX",
  "CATEGORY_SOCIAL",
  "UNREAD"
 ],
 "snippet": "Snippet of the message",
 "historyId": "701108",
 "internalDate": "1451873198000",
 "payload": {
  "mimeType": "multipart/alternative",
...