[英]Google Script GmailApp - Really Confused
I found a script online that allows me to auto delete emails of a certain label that are older than a certain date. 我在网上找到了一个脚本,该脚本可让我自动删除早于特定日期的特定标签的电子邮件。 I've been trying to modify this script to work for me. 我一直在尝试修改此脚本以适合我。 I was able to run it once but got a timeout error saying my script was making too many request to the server. 我能够运行一次,但是出现超时错误,提示我的脚本向服务器发出太多请求。 Everytime after that when I tried to run the script I get a server error. 之后,每次尝试运行脚本时,都会收到服务器错误。 Upon investigating this error using the Execution Transcript int he editor it says I don't have authorization to run the script against my gmail account. 在使用执行成绩int调查此错误后,他的编辑器说我无权针对我的gmail帐户运行脚本。 How do I reauthorize this script so that I can run it and test that it is working? 如何重新授权此脚本,以便我可以运行它并测试它是否正常工作?
function cleanUpForumEmails() {
var delayDays = 30; // Enter # of days before messages are moved to trash
var maxDate = new Date();
maxDate.setDate(maxDate.getDate()-delayDays);
Logger.log("getting gmail labels");
// var label = GmailApp.getUserLabelByName("Social Updates");
var labelObject = GmailApp.getUserLabelByName("Social Updates");
Logger.log("got labels now testing for undefined");
if (labelObject == null) {
Logger.log("Label is NULL");
} else {
var threads = labelObject.getThreads();
Logger.log("Label is Set. Number of Messages in Search: " + threads.length);
for (var i = 0; i < threads.length; i++) {
if (threads[i].getLastMessageDate() < maxDate && threads[i].hasStarredMessages() != true) {
if(i < 10) {
threads[i].moveToTrash();
Logger.log("Moved Email Thread to Trash!");
Utilities.sleep(1000);
} else {
Logger.log("moved 10 threads now breaking");
break;
}
}
}
}
}
If your application is being executed by you and the mail that you want to have access is yours you just need to click in the play button and a windows will appear asking your permission. 如果您正在执行您的应用程序,并且您要访问的邮件是您自己的,则只需单击“播放”按钮,就会出现一个窗口,询问您的许可。 Once this step is completed it will not ask your permission again. 完成此步骤后,将不会再次请求您的许可。
I got it to work by including a call to another google script service. 我通过加入对另一个Google脚本服务的调用来使其工作。 This brought back the authorization page and has been working flawless since then. 从那时起,这又回到了授权页面,并且一直在正常工作。
the line of code that I used was this: 我使用的代码行是这样的:
Session.getActiveUser().getEmail();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.