如何使用android中的gmail api获取用于读取特定邮件的messageID
?
gmail api的users.messages.get
方法需要两个参数:
将是用户名的userId
。messageID
那么,如何才能得到messageID
和messageID
到底是什么呢?
最佳答案
要获得messageIds
,首先需要使用一些可选参数list messages。这将返回messageIds
这只是表示消息的唯一字符串。
常规http请求的示例如下:
只给我一封带有收件箱标签的邮件
userId = me
labelIds = INBOX
maxResults = 1
q = from:me
GET https://www.googleapis.com/gmail/v1/users/me/messages?labelIds=INBOX&maxResults=1&q=from%3Ame
回应:
{
"messages": [
{
"id": "14f8d57248451a6c", // This is the messageId!
"threadId": "14f8d57248451a6c"
}
],
"nextPageToken": "04016634599566360443",
"resultSizeEstimate": 2
}
然后,我在get方法中使用此MessageID获取实际内容:
GET https://www.googleapis.com/gmail/v1/users/me/messages/14f8d57248451a6c
回应:
{
"id": "14f8d57248451a6c",
"threadId": "14f8d57248451a6c",
"labelIds": [
"SENT",
"INBOX",
"IMPORTANT"
],
"snippet": "",
"historyId": "563949",
"internalDate": "1441185342000",
"payload": {
"mimeType": "multipart/mixed",
"filename": "",
"headers": [
{
"name": "MIME-Version",
"value": "1.0"
},
{
"name": "Received",
"value": "by 10.28.99.138 with HTTP; Wed, 2 Sep 2015 02:15:42 -0700 (PDT)"
},
{
"name": "Date",
"value": "Wed, 2 Sep 2015 11:15:42 +0200"
}, ...
如果您想使用一个好的库而不是自己执行请求,那么Android Quickstart可以帮您很大的忙。
关于android - MesageID Android Gmail Api,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32392481/