google-api - Gmail API - 有没有一种方法可以按 w.r.t. 的排序顺序列出邮件?接收时间?

标签 google-api gmail gmail-api

有没有办法使用 Google Mail API 按接收时间排序列出 Gmail 邮件?

虽然 API 返回的邮件是按时间倒序排列的。对于像 10 封邮件这样的非常小的数据集,我发现了差异。

邮件列表API的响应:

 {
 "messages": [
  {
   "id": "15afb61b8d220a19",
   "threadId": "15afb61b8d220a19"
  },
  {
   "id": "15afb618f941d73f",
   "threadId": "15afb618f941d73f"
  },
  {
   "id": "15afb6174711c7af",
   "threadId": "15afb6174711c7af"
  },

  ...
  ...
  {
   "id": "159bc283f63d5eb7",
   "threadId": "159bc283f63d5eb7"
  },
  {
   "id": "159bc283dc97cd87",
   "threadId": "159bc283dc97cd87"
  },
  {
   "id": "159bc283d95f097c",
   "threadId": "159bc283d95f097c"
  }
 ],
 "resultSizeEstimate": 9
}

响应中的第一条消息(最新):

Id: 15afb61b8d220a19
Date: "Thu, 23 Mar 2017 19:06:08 +0530" 
internalDate: "1490276168000"

列表中的第二封邮件:

Id: 15afb618f941d73f
Date: "Thu, 23 Mar 2017 19:05:58 +0530"
internalDate: "1490276158000"

... ... 列表中倒数第二封邮件:

Id: 159bc283dc97cd87 
Date: "Fri, 20 Jan 2017 05:54:30 -0800" 
internalDate: "1484920470000"

列表中的最后一封邮件(应该是最早的,但不是):

Id: 159bc283d95f097c
Date: "Fri, 20 Jan 2017 05:54:31 -0800"
internalDate: "1484920471000"

最佳答案

我猜这是基于此 thread 的预期行为.

...messages.list does NOT return in date ASC or date DESC. They are returned randomly as far as I can tell.

您还可以使用 search syntax按电子邮件的日期过滤。

关于google-api - Gmail API - 有没有一种方法可以按 w.r.t. 的排序顺序列出邮件?接收时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43072057/

相关文章:

google-maps-api-3 - 谷歌距离矩阵 API

google-api - 如何为 Google 服务帐户设置友好名称?

php - 如何实现 Gmail OAuth API 来发送电子邮件(尤其是通过 SMTP)?

email - 如何解码电子邮件的内容?

javascript - 在内容脚本的 chrome 扩展中使用 Gmail Api

google-api - Google DriveService C# 泄漏 HttpConnection 对象

node.js - 使用 OAuth2 在 Node.js 中获取刷新 token 和 Gmail 用户配置文件

sockets - 使用 S22 ImapClient 接收 Gmail 电子邮件时,尝试对无法访问的网络进行套接字操作 [2a00:1450:4013:c01::6d]:993

java - 如何从自定义 Gmail 域发送邮件?

python - 如何获取 Gmail API 邮件的文本/纯文本部分