GMail API:获取收件箱中最旧的电子邮件的最快方法 [英] GMail API: Fastest way to get the oldest email in inbox

查看:567
本文介绍了GMail API:获取收件箱中最旧的电子邮件的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在GMail收件箱中收到最早的电子邮件。我怎样才能用最少的API调用来做到这一点?

I want to get the oldest email in GMail inbox. How can I do that with the minimum number of API calls?

一种方法可以从用户中获得电子邮件的总数:getProfile API,然后使用 User.messages:list API使用 pageToken 查询参数获取最后一页通过使用公式

One way to do it could be to get the total number of emails from Users:getProfile API and then use User.messages:list API to get the last page using "pageToken" query parameter by using the formula


pageToken = totalMessages / 50

pageToken = totalMessages/50

从我的收件箱的最后一页获取消息列表,然后使用列表中最后一条消息的 mid 获取最旧的电子邮件。

to get the list of messages from the last page of my inbox and then using the mid of the last message in the list to fetch the oldest email.

我只是想知道是否有更好的方法来做到这一点?我无法找到其他方法从文档中做到这一点。任何搜索过滤器,将获取我最旧的电子邮件?

I am just wondering if there is a better way to do this? I could not figure out other ways to do it from the documentation. Any search filter that will fetch me the oldest email?

推荐答案

User.messages.list 包含一个名为q的参数,可用于搜索。

User.messages.list contains a paramter called q which can be used for searching.


https://www.googleapis.com/gmail/v1/users/userId/messagesq=before%3A2008%2F01%2F01&access_token= {令牌}

https://www.googleapis.com/gmail/v1/users/userId/messagesq=before%3A2008%2F01%2F01&access_token={token}

基本上之前:2008/01/01 在gmail web应用程序中搜索将返回该日期之前的所有电子邮件。

Basicly before:2008/01/01 is sent just like searching in the gmail web app return all the emails before that date.

这里的技巧将缩小您的搜索范围。 Gmail于2004年发布。在2018年至2004年期间,可能开始将它分成两半:2011年1月1日之前将其分成一半

The trick here will be narrowing down your search. Gmail was released on 2004. Which gives yo possible start between 2018 and 2004 split it in half

before:2011/01/01  (there were mails split it in half again) 
before:2007/01/01  (there were no mails must be between 11 and 7)
before:2009/01/01  (...)

这种搜索方法有一个术语,但我现在不能记住它。基本上,你不断将它除以2,并找出结果必须在哪里。

There is a term for this method of searching but i cant remember it right now. Basically you keep dividing it by two and finding out where the result must be.

这篇关于GMail API:获取收件箱中最旧的电子邮件的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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