首页 > 解决方案 > 从 Gmail.Users.history.list API 检索历史列表时出错

问题描述

我正在尝试检索历史列表并使用 Gmail API 找出新添加的消息。我正在使用 Google 脚本来执行此操作。

这是我定义的监视请求。我将响应的 historyId 分配给histId变量。

var watchResource = Gmail.newWatchRequest();
  watchResource.labelIds = ["INBOX"];
  watchResource.labelFilterAction = "include";
  watchResource.topicName = "projects/project-id-xxxxxxxxxxxx/topics/gmailTrigger";
  
  var response = Gmail.Users.watch(watchResource, userId);
  var histId = response.historyId;

我正在使用这种方法来获取历史列表。

var his = Gmail.Users.History.list(userId,{'startHistoryId': histId});
Logger.log(his);

当我使用histId变量作为“startHistoryId”的参数时,它应该向我发送收件箱的历史列表。但这并没有给我预期的输出。

预期输出 - “{historyId=7092010, history=[{messagesAdded=[{message={threadId=16xxxxxxxxxf, labelIds=[UNREAD, CATEGORY_FORUMS, Label_24593xxxxxxxxxx7]}”

我得到的输出 - “{historyId=7092010}”

但是,当我将从响应 (response.historyId) 收到的 historyId 硬编码到上述代码时,它给了我预期的输出。

var his = Gmail.Users.History.list(userId,{startHistoryId: 7092010});
Logger.log(his);

有人可以帮我弄这个吗?我需要使用该变量而不对其进行硬编码。

标签: google-apps-scriptgmail-api

解决方案


推荐阅读