【问题标题】:How to get the message which is having less than 10 MB size from google gmail js api?如何从 google gmail js api 获取小于 10 MB 的消息?
【发布时间】:2018-11-18 09:29:04
【问题描述】:

我正在我的应用程序中进行一些端点调用。我只想获取大小小于 10 MB 的电子邮件。那么有没有办法将任何查询参数传递给 gmail 端点,所以它只会给我预期的结果?

https://developers.google.com/gmail/api/v1/reference/users/messages/get

此网址包含获取消息的文档,但没有写如何限制数据。

这是性能提示(https://developers.google.com/gmail/api/guides/performance),但这里也不清楚。

请帮帮我。

提前致谢。

【问题讨论】:

    标签: node.js google-api gmail-api


    【解决方案1】:

    这个答案怎么样?您可以使用gmail.users.messages.list 的查询按大小检索邮件。当您要检索小于 10 MBytes 的邮件时,请使用smaller:10M 作为查询。如果您要检索大小超过 10 MBytes 的邮件,请使用larger:10M。通过使用此查询检索消息 ID,您可以使用 gmail.users.messages.get 按 ID 检索消息。

    node.js 的示例脚本如下。在此示例中,可以检索大小小于 10 MBytes 的邮件的消息 ID。

    示例脚本:

    const gmail = google.gmail({version: 'v1', auth});
    gmail.users.messages.list({
      userId: 'me',
      q: 'smaller:10M',
    }, (err, {data}) => {
      if (err) return console.log('The API returned an error: ' + err);
      data.messages.forEach((e) => console.log(e.id));
    });
    

    参考资料:

    如果我误解了你的问题,我很抱歉。

    【讨论】:

    • 非常感谢@Tanaike。它对我有用,你以完美的方式回答了我的问题。再次感谢。
    • @Shravan Jain 欢迎您。我很高兴你的问题得到了解决。也谢谢你。
    猜你喜欢
    • 1970-01-01
    • 2015-10-05
    • 2016-09-21
    • 1970-01-01
    • 2016-03-18
    • 2015-06-07
    • 2018-01-17
    • 2018-07-06
    • 1970-01-01
    相关资源
    最近更新 更多