获取标签 ID 以使用 GMAIL API 获取邮件列表 [英] Get Label ID to get a List of Messages with GMAIL API

查看:46
本文介绍了获取标签 ID 以使用 GMAIL API 获取邮件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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...

有什么想法吗?

迭戈.

推荐答案

Label ID 与 Label Name 相同,仅用于系统生成的标签.例如聊天、发送、收件箱、垃圾箱等

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.

获取它们的最简单方法是使用 imCaps 提到的 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 获取邮件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆