api - Gmail.Users.Messages.remove(me, id) - 未找到错误

标签 api google-apps-script gmail

有没有其他人发现Advanced Gmail Service调用

`Gmail.Users.Messages.remove(me, id)`

现在出现错误?有人有办法解决吗?

我有一个可靠的脚本,每隔几个小时就会删除垃圾邮件和垃圾邮件。从 2017 年 2 月 21 日左右开始,即使传递了有效的线程 ID,它也会给出错误“未找到”。

这是脚本。我添加了一些日志消息

function deleteForever() {
  var threads = GmailApp.getSpamThreads(0, 100);
  var me = Session.getActiveUser().getEmail();
  for (var i = threads.length -1; i >=0; i--) {
     var thisid=threads[i].getId();
        Logger.log("Removing thread " +i + ' of ' + threads.length + " from Spam with ID = " + thisid);

    try {
    var thisthread=GmailApp.getThreadById(thisid);
    Logger.log("Found the thread.");
    Gmail.Users.Messages.remove(me, thisid);
    }catch(err) {
     Logger.log("Error " + err.message);
    };

  }
  Logger.log("Finished removing " + threads.length + " threads from Spam.");

  var threads = GmailApp.getTrashThreads(0, 100);
  for (var i = threads.length -1; i >=0; i--) {
        Logger.log("Removing thread " +i + ' of ' + threads.length + " from Trash");
    try {
    Gmail.Users.Messages.remove(me, threads[i].getId());
    } catch(err) {
    Logger.log("Error " + err.message);
    };
  }
  Logger.log("Finished removing " + threads.length + " threads from Trash.");
}

现在它只是给出一个未找到的错误。

[17-02-25 11:45:49:790 GMT] Removing thread 17 of 18 from Spam with ID = 15a6fe6c1a86a020
[17-02-25 11:45:49:829 GMT] Found the thread.
[17-02-25 11:45:49:959 GMT] Error Not Found
[17-02-25 11:45:49:959 GMT] Removing thread 16 of 18 from Spam with ID = 15a6fe6c168f4a03
[17-02-25 11:45:50:000 GMT] Found the thread.
[17-02-25 11:45:50:129 GMT] Error Not Found
[17-02-25 11:45:50:130 GMT] Removing thread 15 of 18 from Spam with ID = 15a6fed29f6650b3
[17-02-25 11:45:50:165 GMT] Found the thread.
[17-02-25 11:45:50:294 GMT] Error Not Found
.....
    `

请注意,在尝试删除操作之前,thisid 已明确设置为有效 ID。

最佳答案

您正在删除消息,而搜索功能正在获取线程。

使用

Gmail.Users.Threads.remove("me", threadId)

代替

Gmail.Users.Messages.remove("me", threadId);

关于api - Gmail.Users.Messages.remove(me, id) - 未找到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42455747/

相关文章:

asp.net - 使用 ASP .Net 和 Gmail SMTP 发送电子邮件

email - Jenkins 电子邮件插件 : Could not connect to SMTP host: smtp. gmail.com,端口:465;

ruby-on-rails - 如何为 apipie-rails gem 生成 header ?

javascript - Wordpress API,React : this. state.project.title 未定义

javascript - ES256 的 JWT 签名要求

javascript - setBackGroundRGB 不接受字符串

jquery - 无法为 jquery 表单单击找到正确的选择器

javascript - 如何从循环范围内计数

google-apps-script - 在 Google Sheets 宏/脚本中,日期被复制为 "Range"

google-apps-script - 如何使用 GMail 查询语言过滤没有附件的邮件?