问题
I am using the new GMAIL API v1 that Google launched some days ago.
I want to get the list of some emails filtering with some labels. If I want to do that, I need to get the label ID of each "label_name" but I just can get the list of all of labels...
Any idea?
Diego.
回答1:
Well, I have used:
ListMessagesResponse messagesWithLabels = service.users().messages().list("me").setQ("label:mylabel").execute();
It is working :)
回答2:
LABEL ID is the same LABEL NAME.
{
"id": "INBOX",
"name": "INBOX",
"messageListVisibility": "hide",
"labelListVisibility": "labelShow",
"type": "system"
}
try here API Explorer with your credentials.
回答3:
Label ID is the same as Label Name only for system generated labels. For example CHAT, SENT, INBOX, TRASH, etc.
User-generated labels have IDs that are different from their names.
The easiest way to get them is to use the API explorer that imCaps mentioned.
Alternatively, you can use this
function listLabels() {
var request = Gmail.Users.Labels.list('me');
var name, id;
for (var l = 0 ; l < request.labels.length; l++) {
name = request.labels[l].name;
id = request.labels[l].id;
Logger.log("%s. %s %s", l, name, id)
}
}
You'll need to enable the Gmail API in Advanced Google Services for this code to work.
来源:https://stackoverflow.com/questions/24484970/get-label-id-to-get-a-list-of-messages-with-gmail-api