您可以非常轻松地在Users.thread:get-request中选择所需的标题,如下所示:
format = metadata
metadataHeaders = From
GET https://www.googleapis.com/gmail/v1/users/me/threads/14eaffaf5e3e8242?metadataHeaders=From&format=metadata&key={YOUR_API_KEY}
响应:
{
"id": "14eaffaf5e3e8242",
"historyId": "510358",
"messages": [
{
"id": "14eaffaf5e3e8242",
"threadId": "14eaffaf5e3e8242",
"labelIds": [
"SENT",
"INBOX",
"IMPORTANT"
],
"snippet": "Wow Emil!",
"historyId": "510292",
"internalDate": "1437471536000",
"payload": {
"mimeType": "multipart/mixed",
"headers": [
{
"name": "From", // I just got the header I asked for.
"value": "Emil Tholin <emtholin@gmail.com>"
}
]
},
"sizeEstimate": 9260
}, ...
}
您还可以非常轻松地获得身体的某些部位。例如。在这里,我要求邮件正文中所有附件的attachmentIds:
field = messages/id,messages/payload/parts/body/attachmentId
GET https://www.googleapis.com/gmail/v1/users/me/threads/14eaffaf5e3e8242?fields=messages%2Fid%2Cmessages%2Fpayload%2Fparts%2Fbody%2FattachmentId&key={YOUR_API_KEY}
回复:
{
"messages": [
{
"id": "14eaffaf5e3e8242",
"payload": {
"parts": [
{
"body": { // This message had an attachment.
"attachmentId": "ANGjdJ_0lphTo48BO0xBT_YOSo3tYah23hzpjyATe3GwfziK0I6401P_8-ZYoGuCQPHhpPP0-S_pjL68WIEZzQ0tu72RcIOE4UY3kA4u8PjXPf3Cm5PxVJjmH9N0hm0fFX31RYo8bfZQ6l7bDbYbnCSZbckG7g8enGaKMPbBzIEEC4HXr_YghOYWSfrXKXiFLnxWN4LfsFk3IXUN2tVvMe_0xMhDDfBlqYPnXHr2PhPghq7bQojNxiH4YziIqaKmwiU4xqVfygbae-K-_Q2blyz0EgI4OXjMzwz56Q5e1w"
}
}
]
}
},
{
"id": "14eaffb277b61cd0" // This message had no attachment.
}, ...
]
}
正如您在第一个请求中看到的那样,在请求特定元数据标头时,不会检索正文的任何部分。单个字段也很难在fields
- 参数中选择,因为标题不是键值对,而是{ "name": <HEADER_NAME>, "value": <HEADER_VALUE> }
形式的对象。
有没有办法合并这两个请求?我希望获得有关消息的所有相关元数据,同时获取消息中有多少附件。
答案 0 :(得分:1)
&#34; metadata&#34;:返回带有消息元数据的电子邮件标头,例如标识符和标签。
fields参数仅用于限制返回的数据量。由于Activity
模式已经是有限响应,因此您无法使用字段来获取该子集之外的数据。您最好的选择是将第二个示例与字段一起使用,然后在本地过滤元数据值。