Gmail REST API获取消息功能返回无效的historyId [英] Gmail REST API get message function returns invalid historyId

查看:53
本文介绍了Gmail REST API获取消息功能返回无效的historyId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Gmail REST API中似乎有一个严重的问题.

It seems like there may be a serious issue in the Gmail REST API.

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

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

The result is unexpected. The Gmail REST API is returning 404 Not Found.. It seems the returned historyId is not registered or valid.

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

On calling /userId/profile, the startHistoryId is valid and can be used successfully in the /userId/history/list call.

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

推荐答案

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

This is not a bug in the API and is documented at https://developers.google.com/gmail/api/v1/reference/users/history/list

具体来说,历史记录ID按时间顺序递增,但不与有效ID之间的随机间隔连续.提供无效或过时的startHistoryId通常会返回HTTP 404错误代码.historyId通常至少有效一周,但在在某些情况下可能只适用几个小时.如果收到HTTP 404错误响应,则您的应用程序应执行完全同步."

Specifically "History IDs increase chronologically but are not contiguous with random gaps in between valid IDs. Supplying an invalid or out of date startHistoryId typically returns an HTTP 404 error code. A historyId is typically valid for at least a week, but in some circumstances may be valid for only a few hours. If you receive an HTTP 404 error response, your application should perform a full sync."

因此,您可能只使用了一个historyId,它在存储的历史记录范围之外(不是无限期地存储,这将非常昂贵).它只存储了足够长的时间,无法同步客户端以使用它(例如一周左右).

So you are likely just using a historyId that is outside the range of history stored (it's not stored indefinitely, that would be very expensive). It's only stored long enough for syncing clients to need it (e.g. a week or so).

如果只需要从某个特定点向前同步,则只需使用从getProfile返回的historyId.消息上的historyId是消息的最后更新时间,可能是几个月或几年前,比历史记录存储的时间长.

If you just need to sync from a certain point forward then just use the historyId returned from getProfile. The historyId on a message was when the message was last updated, which could be months or years ago, longer than history is stored.

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

See also the sync'ing guide: https://developers.google.com/gmail/api/guides/sync

这篇关于Gmail REST API获取消息功能返回无效的historyId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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