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.
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.
Well, I have used:
ListMessagesResponse messagesWithLabels = service.users().messages().list("me").setQ("label:mylabel").execute();
It is working :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With