gpt4 book ai didi

javascript - TypeError : Cannot call method "getThreads" of null.(第 59 行)+ 1 个其他错误

转载 作者:行者123 更新时间:2023-11-28 09:39:27 24 4
gpt4 key购买 nike

我对 Javascript 的了解很少,但想使用此代码来增强我的 GMail 体验。它有效,但我也遇到错误。当我在 Google Spreadsheet 中运行调试器时,两个函数似乎出现故障:

TypeError: Cannot call method "getThreads" of null. (line 59)

具有以下执行记录

GmailApp.getUserLabelByName([FollowUp])

GmailApp.getUserLabelByName([FollowUp/1undefined])

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

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

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

Cannot find method moveThreadsToInbox(. (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

最佳答案

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

关于javascript - TypeError : Cannot call method "getThreads" of null.(第 59 行)+ 1 个其他错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12562748/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com