问题描述
我正在使用Google几天前启动的新GMAIL API v1.
I am using the new GMAIL API v1 that Google launched some days ago.
我想获取一些带有某些标签过滤的电子邮件的列表.如果我想这样做,我需要获取每个"label_name"的标签ID ,但我可以获取所有标签的列表...
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...
有什么主意吗?
迭戈.
推荐答案
标签ID仅对于系统生成的标签与标签名称"相同.例如CHAT,SENT,INBOX,TRASH等.
Label ID is the same as Label Name only for system generated labels. For example CHAT, SENT, INBOX, TRASH, etc.
用户生成的标签的ID与名称不同.
User-generated labels have IDs that are different from their names.
获取它们的最简单方法是使用 API资源管理器.
The easiest way to get them is to use the API explorer that imCaps mentioned.
或者,您可以使用
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)
}
}
您需要在高级Google服务中启用Gmail API,此代码才能正常工作.
You'll need to enable the Gmail API in Advanced Google Services for this code to work.
这篇关于获取标签ID,以使用GMAIL API获取消息列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!