Google 脚本:无法检索(第 9 行,文件“代码”)

1 google-apps-script

我正在尝试设置我的第一个 Google 脚本。它应该从符合我的搜索条件的电子邮件集中删除标签,但是当我运行脚本时,我收到此错误:

Cannot retrieve (line 9, file "Code")
Run Code Online (Sandbox Code Playgroud)

我的代码:

function ArchiveEmails() {
  var misc_reps = GmailApp.search("from:(reports@example.com) \"Source: misc_reports\" \"The file was successfully processed\"");
  var imp_tms_processing = GmailApp.getUserLabelByName('imp-tms-processing');


  for (var i=0; i<misc_reps.length; i++) {
    var misc_rep = misc_reps[i];
    var id_string = misc_rep.getId(); //use to confirm specific email found in debugging
    misc_rep.removeLabel(imp_tms_processing); // line 9
  }  
}
Run Code Online (Sandbox Code Playgroud)

我不知道从这里该去哪里;我找不到关于这个问题的任何文档。

Sha*_*ley 5

这意味着 Gmail 找不到该标签。你可能会认为这一行会发生错误:

var imp_tms_processing = GmailApp.getUserLabelByName('imp-tms-processing');
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,它不会抛出错误,直到您真正尝试对标签执行某些操作。

登录 Gmail 帐户并确保您的标签存在。如果您的标签嵌套在父标签下,请使用以下形式:

GmailApp.getUserLabelByName("parent/child");
Run Code Online (Sandbox Code Playgroud)