问题
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