1

我对 Javascript 知之甚少,但想使用此代码来增强我的 GMail 体验。它有效,但我也遇到错误。当我在 Google 电子表格中运行调试器时,两个函数出现故障:

TypeError:无法调用 null 的方法“getThreads”。(第 59 行)

使用以下执行记录

GmailApp.getUserLabelByName([FollowUp])

GmailApp.getUserLabelByName([FollowUp/1undefined])

插入评论:这里有一些关于 GMail API 调用 getThreads(和其他)的信息:https ://developers.google.com/apps-script/class_gmaillabel#getThreads

我不明白为什么它调用 Followup/1undefined -> 为什么它是未定义的?应该是Followup/1days

另一个函数的另一个错误:

找不到方法 moveThreadsT​​oInbox(. (line 26)

执行记录中没有任何内容

整个代码是:

// Adapted from:
// http://gmailblog.blogspot.com/2011/07/gmail-snooze-with-apps-script.html
//
// To setup:
// - From the |Run| menu select |setup|
//   - if prompted to authorize, do so, and then repeat this step.
//
// - Verify the script is set to be triggered to run
//   - |Triggers| menu |Current script's triggers...|
//   - 3 triggers should exist to call e.g. 
//     - dailyUpdate, Time Driven, Daily

function getLabelName(i, labelSuffixString) {
  return "FollowUp/" + i + labelSuffixString;
}

function setup() {
  for (var i = 1; i <= 7; ++i) {
    GmailApp.createLabel(getLabelName(i, "days"));
    GmailApp.createLabel(getLabelName(i, "weeks"));
  }
  GmailApp.createLabel("FollowUp");
}

function moveToInbox(page) {
  GmailApp.moveThreadsToInbox(page);
  GmailApp.markThreadsImportant(page);
}

function cleanOldFollowUpLabels() {
  var searchString = "-label:inbox label:FollowUp";
  for (var i = 1; i <= 7; ++i) {
    searchString += " -label:" + getLabelName(i, "days");
    searchString += " -label:" + getLabelName(i, "weeks");
  }
  searchString = searchString.replace(RegExp("/", "g"), "-");
  Logger.log("cleanOldFollowUpLabels() Search String:");
  Logger.log(searchString);
  var followUpLabel = GmailApp.getUserLabelByName("FollowUp");  
  var page = null;
  // Get threads in "pages" of 100 at a time
  while(!page || page.length == 100) {
    page = GmailApp.search(searchString, 0, 100);
    Logger.log("found: " + page.length);
    if (page.length > 0)
      followUpLabel.removeFromThreads(page);   
  }
}

function update(labelSuffixString) {
  var oldLabel, newLabel, page;
  var followUpLabel = GmailApp.getUserLabelByName("FollowUp");
  for (var i = 1; i <= 7; ++i) {
    newLabel = oldLabel;
    oldLabel = GmailApp.getUserLabelByName(getLabelName(i, labelSuffixString));
    page = null;
    // Get threads in "pages" of 100 at a time
    while(!page || page.length == 100) {
      page = oldLabel.getThreads(0, 100);
      if (page.length > 0) {
        followUpLabel.addToThreads(page);
        if (newLabel) {
          // Move the threads into "today’s" label
          newLabel.addToThreads(page);
        } else {
          moveToInbox(page);
        }     
        // Move the threads out of "yesterday’s" label
        oldLabel.removeFromThreads(page);
      }  
    }
  }
}

function dailyUpdate() {
  update("days");
}
function weeklyUpdate() {
  update("weeks");
}

也在这里: http: //pastie.org/4790086.js

4

1 回答 1

0

mm..在同事的帮助下,我们找到了自己问题的答案。我运行了三个触发器:每日触发器、每周触发器和更新触发器。现在更新触发器不是必需的,因为它是由每日和每周触发器调用的,并且没有任何输入。这导致了错误。现在我必须等待,看看是否有任何错误以及脚本是否有效。

于 2012-09-27T13:19:17.760 回答