【问题标题】:Gmail REST API get message function returns invalid historyIdGmail REST API 获取消息函数返回无效的 historyId
【发布时间】:2015-06-30 08:02:54
【问题描述】:

Gmail REST API 中似乎存在严重问题。

  1. 调用/userId/messages获取消息列表
  2. 对于每个,调用 /userId/messages/id 来获取消息
  3. 获取每个消息对象的最高(或任何)startHistoryId
  4. 然后调用 /userId/history/list 传递 startHistoryId 作为参数

结果出乎意料。 Gmail REST API 返回 404 Not Found.. 返回的 historyId 似乎未注册或无效。

在调用 /userId/profile 时,startHistoryId 有效,可以在 /userId/history/list 调用中成功使用。

com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
{
"code" : 404,
"errors" : [ {
     "domain" : "global",
     "message" : "Not Found",
     "reason" : "notFound"
    } ],
  "message" : "Not Found"
}

【问题讨论】:

  • 这是因为 Gmail 仅在创建邮件时才为邮件创建 historyId?如果消息是很久以前创建的,那么历史引用会被删除吗?

标签: gmail-api


【解决方案1】:

这不是 API 中的错误,记录在 https://developers.google.com/gmail/api/v1/reference/users/history/list

特别是“历史 ID 按时间顺序增加,但与有效 ID 之间的随机间隔不连续。提供无效或过期的 startHistoryId 通常会返回 HTTP 404 错误代码。historyId 通常至少在一周内有效,但在某些情况下可能仅在几个小时内有效。如果您收到 HTTP 404 错误响应,您的应用程序应该执行完全同步。"

因此,您可能只是使用了超出存储历史范围的 historyId(它不会无限期存储,这将非常昂贵)。它仅存储足够长的时间以供同步客户端需要它(例如一周左右)。

如果您只需要从某个点向前同步,那么只需使用从 getProfile 返回的 historyId。消息上的 historyId 是消息最后一次更新的时间,可能是几个月或几年前,比历史存储的时间长。

另请参阅同步指南: https://developers.google.com/gmail/api/guides/sync

【讨论】:

  • 这就是我一直在寻找的东西,但是我遇到了一个奇怪的问题,也许你可以解释一下。用户在 messages.list {resultsSizeEstimate:0} 中没有任何内容。所以我从 getProfile 中获取 historyId 来进行部分同步。但是,当我尝试使用 startHistoryId 提取 history.list 时,它返回 404。这对这个邮箱的状态意味着什么?是不是最新的startHistoryId也是过期了,说明邮箱很久没用了?
猜你喜欢
  • 2015-10-26
  • 2023-03-18
  • 2015-11-10
  • 1970-01-01
  • 1970-01-01
  • 2016-03-18
  • 1970-01-01
  • 2018-02-22
  • 1970-01-01
相关资源
最近更新 更多