Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Gmail API getMessage方法为从listHistory方法获取的消息返回404_Node.js_Google Api_Gmail_Gmail Api - Fatal编程技术网

Node.js Gmail API getMessage方法为从listHistory方法获取的消息返回404

Node.js Gmail API getMessage方法为从listHistory方法获取的消息返回404,node.js,google-api,gmail,gmail-api,Node.js,Google Api,Gmail,Gmail Api,对问题的简短描述: 我们的同步设置如下: 通过调用messages.list方法对用户的收件箱执行完全同步。 从响应中保存最高的historyId 在向我们的webhook端点发送推送通知时,使用我们以前保存的startHistoryId调用history.list 使用响应的messagesAdded部分中的消息ID(我们排除messagesDeleted部分中的消息和带有标签草稿的消息),在Gmail API上调用messages.get方法。 Gmail API随机返回404错误(“未找到

对问题的简短描述:

我们的同步设置如下:

通过调用messages.list方法对用户的收件箱执行完全同步。 从响应中保存最高的historyId 在向我们的webhook端点发送推送通知时,使用我们以前保存的startHistoryId调用history.list 使用响应的messagesAdded部分中的消息ID(我们排除messagesDeleted部分中的消息和带有标签草稿的消息),在Gmail API上调用messages.get方法。 Gmail API随机返回404错误(“未找到请求的实体”)。这通常以突发方式发生(但并非总是如此),其中30-50条据称添加的消息返回404条。我已经确认用户没有设置可能导致它的自动过滤器。它也发生在工作时间以外,这意味着用户不可能删除这些消息。 例如:

使用historyId 463077调用listHistory 响应中返回了以下消息:

{
  id: '1762a36a2ab4ab29',
  threadId: '175e5e4219f86042',
  labelIds: [ 'UNREAD', 'IMPORTANT', 'CATEGORY_PERSONAL', 'INBOX' ]
}
getMessage为该特定消息返回404(未找到请求的实体)。时间戳2020-12-03T20:06:42.392Z 可靠地再现问题的小代码示例。该示例应按原样运行,或以最少的设置运行,无外部依赖关系

我们正在使用googleapis 47.0.0节点包

  let addedMessageIds: string[] = [];
  let deletedMessageIds: string[] = [];
  let nextPageToken: undefined | string;
  const numbers: number[] = [];
  while (true) {
    const result = await gmail.users.history.list({
      startHistoryId: '664689',
      pageToken: nextPageToken,
      userId: 'me',
      labelId: 'INBOX',
      historyTypes: ['MESSAGE_ADDED', 'MESSAGE_DELETED'],
    });

    for (const historyMessage of result.data.history || []) {
      for (const deleted of historyMessage.messagesDeleted || []) {
        if (!deleted.message?.id) continue;
        deletedMessageIds.push(deleted.message.id);
      }

      for (const added of historyMessage.messagesAdded || []) {
        if (!added.message?.id) continue;
        addedMessageIds.push(added.message.id);
      }
    }

    if (!result.data.nextPageToken) break;
    nextPageToken = result.data.nextPageToken;
  }
  
  for (const id of addedMessageIds) {
    if (deletedMessageIds.includes(id)) continue;
    try {
      await gmail.users.messages.get({
        id: id,
        userId: 'me',
      });
    } catch (e) {
      console.error('DID NOT GET MESSAGE', {
        messageId: id,
        error: e.message,
      });
    }    
  }
Google云平台的度量报告getMessage方法的错误率约为76%。通过比较系统中的消息ID,我们仍然能够获得大部分消息,但不是全部。由于错误率始终高于0,我们无法确定是否收到了消息

为什么在使用getMessage检索listHistory调用返回的消息ID时会收到404错误?

这似乎是一个错误! 我自己无法复制这个问题,但已经有一份关于谷歌问题追踪者的报告详细描述了同样的行为(尽管这可能是你的报告):

谷歌似乎确实从他们的回复中了解到了这个问题,所以我建议遵循这个问题线索,并在那里提供额外的信息来帮助解决这个问题

您还可以点击☆ 在上述页面左上角的发行号旁边,谷歌知道有更多的人遇到了这一问题,因此更有可能看到它更快

我希望这对你有帮助

这似乎是一个错误! 我自己无法复制这个问题,但已经有一份关于谷歌问题追踪者的报告详细描述了同样的行为(尽管这可能是你的报告):

谷歌似乎确实从他们的回复中了解到了这个问题,所以我建议遵循这个问题线索,并在那里提供额外的信息来帮助解决这个问题

您还可以点击☆ 在上述页面左上角的发行号旁边,谷歌知道有更多的人遇到了这一问题,因此更有可能看到它更快


我希望这对你有帮助

那么你的问题到底是什么@JeremyDurrance@ale13这是一个为什么我们在使用getMessage检索listHistory调用返回的消息ID时会收到404错误的问题?那么您的问题到底是什么@JeremyDurrance@ale13问题是,当使用getMessage检索listHistory调用返回的消息ID时,为什么会收到404错误?