How to get message flags like “seen” in Gmail API

*爱你&永不变心* 提交于 2019-12-08 04:55:45

问题


I'm trying to get email messages from Gmail using the RESTful API and I don't see how can I get message flags (read / unread and etc.). Is there any way to get message flags from the Gmail using the RESTful API?

Thanks.


回答1:


What do you mean by "flags" and "folders"? are you used to using IMAP and referring to it in that sense? what you normally would want is to look at labels like "UNREAD". those labels are the hardcoded, system labels and are documented at: https://developers.google.com/gmail/api/guides/labels

they are those exact values, never translated to other languages like the web user interface is.

gmail doesn't have "flags" or "folders" just labels. the flags and folder concepts are (somewhat hackily) provided to support IMAP. if you want to see all the unread message in the inbox just do something like:

>>> messages.list(labelIds=["INBOX", "UNREAD'])



回答2:


Read/Unread status for a message is indicated by the presence of the UNREAD label. You can also see whether a message is starred. See Managing Labels.




回答3:


You can do it as:

ListMessagesResponse emails = service.users().messages().list("me").setQ("label:UNREAD").execute();
// Getting my unread mails.

And it works with whatever language.



来源:https://stackoverflow.com/questions/24936724/how-to-get-message-flags-like-seen-in-gmail-api

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