Gmail REST API get message function returns invalid historyId

不问归期 提交于 2019-11-28 08:26:30

问题


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

  1. Call /userId/messages to obtain a list of message
  2. For each, call /userId/messages/id to get the message
  3. Obtain the highest (or any) startHistoryId on each message object
  4. Then call /userId/history/list passing startHistoryId as a parameter

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

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"
}

回答1:


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

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."

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).

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.

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



来源:https://stackoverflow.com/questions/29801366/gmail-rest-api-get-message-function-returns-invalid-historyid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!