Gmail API Users.messages: list

眉间皱痕 提交于 2019-11-27 23:57:55

message.list() only returns the ids of the messages, as is pretty standard REST behavior to keep the response small and fast. If you also need to get more info on the messages (such as the labels) you'd need to followup with something like message.get(id=$THAT_ID, format=MINIMAL), which you can call using batch to retrieve for many messages in parallel.

I believe you should be doing it the other way around. Get the list of labels and for each label get the messages.

INBOX itself is a label which will let you get the Primary emails (emails in the 'Primary' tab)

Get the list of labels here: https://developers.google.com/gmail/api/v1/reference/users/labels/list

When getting messages provide the labelId(s).

Also CATEGORY_UPDATES, INBOX, CATEGORY_PROMOTIONS are itself Ids and as well as names.

I hope this helps to handle your requirement.

After getting the response as

{
 "messages": [
  {
   "id": "146da54fe3dc089e",
   "threadId": "146da54fe3dc089e"
  },
  {
   "id": "146da41d9486982f",
   "threadId": "146da41d9486982f"
  },
  ...
}

You can use the following method to get the Label IDs from each mail using the id,

https://www.googleapis.com/gmail/v1/users/<userId>/messages/<messageId>

Reference : Users.messages: get

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!