gmail-api - Gmail REST API获取消息功能返回无效的historyId

标签 gmail-api

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

  • 调用/userId/messages获得消息列表
  • 对于每一个,调用/userId/messages/id以获取消息
  • 在每个消息对象
  • 上获得最高的(或任何)startHistoryId
  • 然后通过传递startHistoryId作为参数
  • 来调用/userId/history/list

    结果是意外的。 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"
    }
    

    最佳答案

    这不是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

    关于gmail-api - Gmail REST API获取消息功能返回无效的historyId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29801366/

    相关文章:

    java - 无法在 JAVA 中使用 GMAIL api 获取前 10 条消息?

    android - 使用 Android 的 Gmail API 访问

    c# - 使用 mimekit/mailkit 库获取电子邮件的传递状态

    gmail-api - GMAIL API 在 C# 中发送带附件的电子邮件

    google-apps-script - 为什么 GmailDraft.send() 会使草稿的 gmail 标签消失?

    java - 群发邮件失败 421 4.7.0 稍后再试

    c# - Gmail API : forcing the authorization to reprompt the user

    python - 修改邮件标签 Python GMAIL API

    python - 如何在新电子邮件中发送现有消息而不丢失格式