我不认为一个特定用户的消息列表的historyId 保证单调增加。
在我检查了包含一些 gmail 用户元数据的数据库之后。我发现没有证据表明historyId 是单调递增的。
这是来自我的 gmail 数据的 historyId 和 internalDate 的一部分。
> db.gmail_threads.find({integrationEmail: 'me@test.com'}, {_id:0,historyId:1, internalDate:1, date:1}).limit(500).sort({internalDate:1})
{ "historyId" : "4745", "date" : "Sun, 11 Sep 2016 02:43:52 -0700 (PDT)", "internalDate" : NumberLong("1473587032000") }
{ "historyId" : "2766", "date" : "Sun, 11 Sep 2016 02:43:57 -0700", "internalDate" : NumberLong("1473587037000") }
{ "historyId" : "2745", "date" : "Sun, 11 Sep 2016 02:43:57 -0700", "internalDate" : NumberLong("1473587037000") }
{ "historyId" : "3116", "date" : "Sun, 11 Sep 2016 02:43:57 -0700", "internalDate" : NumberLong("1473587037000") }
{ "historyId" : "2245", "date" : "Sun, 11 Sep 2016 09:44:31 +0000", "internalDate" : NumberLong("1473587071000") }
{ "historyId" : "2246", "date" : "Sun, 11 Sep 2016 09:44:58 +0000", "internalDate" : NumberLong("1473587098000") }
{ "historyId" : "2254", "date" : "Sun, 11 Sep 2016 09:57:24 +0000", "internalDate" : NumberLong("1473587844000") }
{ "historyId" : "2249", "date" : "Sun, 11 Sep 2016 09:57:31 +0000", "internalDate" : NumberLong("1473587851000") }
{ "historyId" : "2244", "date" : "Sun, 11 Sep 2016 09:57:37 +0000", "internalDate" : NumberLong("1473587857000") }
{ "historyId" : "4749", "date" : "Sun, 11 Sep 2016 09:57:58 +0000", "internalDate" : NumberLong("1473587878000") }
{ "historyId" : "2248", "date" : "Sun, 11 Sep 2016 03:10:57 -0700 (PDT)", "internalDate" : NumberLong("1473588657000") }
{ "historyId" : "3067", "date" : "Sun, 11 Sep 2016 16:21:12 -0700 (PDT)", "internalDate" : NumberLong("1473636072000") }
{ "historyId" : "3026", "date" : "Sun, 11 Sep 2016 16:33:27 -0700 (PDT)", "internalDate" : NumberLong("1473636807000") }
{ "historyId" : "2989", "date" : "Sun, 11 Sep 2016 23:38:35 +0000", "internalDate" : NumberLong("1473637115000") }
{ "historyId" : "5091", "date" : "Sun, 11 Sep 2016 16:42:52 -0700 (PDT)", "internalDate" : NumberLong("1473637372000") }
{ "historyId" : "2322", "date" : "Mon, 12 Sep 2016 01:46:21 -0000", "internalDate" : NumberLong("1473644781000") }
{ "historyId" : "3137", "date" : "Mon, 12 Sep 2016 01:53:24 -0000", "internalDate" : NumberLong("1473645204000") }
{ "historyId" : "2560", "date" : "Sun, 11 Sep 2016 20:17:09 -0700 (PDT)", "internalDate" : NumberLong("1473650229000") }
{ "historyId" : "2678", "date" : "Sun, 11 Sep 2016 22:12:18 -0700 (PDT)", "internalDate" : NumberLong("1473657138000") }
{ "historyId" : "2931", "date" : "Mon, 12 Sep 2016 12:22:54 +0000 (UTC)", "internalDate" : NumberLong("1473682974000") }
Type "it" for more
根据Gmail API documents,限制如下:
历史记录通常至少可以保存一周,通常更长时间。但是,记录可用的时间段可能要少得多,并且有时在极少数情况下记录可能不可用。如果您的客户端提供的 startHistoryId 超出历史记录的可用范围,API 将返回 HTTP 404 错误响应。在这种情况下,您的客户端必须按照上一节所述执行完全同步。