Mikeism
Mikeism

Reputation: 11

My Google script is failing. Authorization issue? Suggestions to fix it?

The deleteOldGmail() function below runs once a week. It ran without issue for a few years, and then sometime in 2016 (October I think) I started to get failure messages as shown below, even though I made zero changes to the script. The failure notice indicates that 'deleteOldGmail Authorization is required to perform that action'; however, I have executed each function in the script to check / re-establish authorization rights and I get zero errors when I run each function.

Failure notice:


Summary of failures for Google Apps Script: deleteOldGmail <-- this is in the Subject field.

The error message: Your script, deleteOldGmail, has recently failed to finish successfully. A summary of the failure(s) is shown below. To configure the triggers for this script, or change your setting for receiving future failure notifications, click here.

Start Function Error Message Trigger End 2/27/17 12:20 AM deleteOldGmail Authorization is required to perform that action. time-based 2/27/17 12:20 AM Sincerely, Google Apps Script


Based on suggestions in this forum I have executed each function individually to fix possible issues related to script authorization rights. I get zero run-time errors; everything seems to run ok.

Function description: 1) deleteOldGmail calls two other functions: deleteOldInboxMsgs and deleteOldPromotionMsgs. In a nutshell, these scripts were written to delete old email. The filter in 'mySearch' is used to ensure that I don't delete old email if I sent it to myself, or if the message contains key words such as 'license', 'registration', 'confirmation', etc.

2) As each function completes, its last action is to send a message indicating that the 'function executed'. I get all these messages without errors. The scripts appear to run successfully a little bit after midnight every Monday; however, an error summary then arrives at 7:28 PM every Monday evening.

Full script shown below. abc.xyz.com is substituted for the real email address used in the script.


function deleteOldGmail() {
  deleteOldInboxMsgs();
  deleteOldPromotionMsgs();
  GmailApp.sendEmail("[email protected]", "deleteOldGmail function completed...", "...the code for this function is in the googleScripts folder of your Google Drive");
}

function deleteOldInboxMsgs() {
  var mySearch = "is:inbox is:unread older_than:700d -from:me -confirmation -account -license -registrar -registration  -'serial number'";
  var batchSize = 100; // Process up to 100 threads at once
  GmailApp.sendEmail("[email protected]", "deleteOldInboxMsgs function executed", " ");
  while (GmailApp.search(mySearch, 0, 1).length == 1)
  {
    GmailApp.moveThreadsToTrash(GmailApp.search(mySearch, 0, batchSize));
  }  
}


function deleteOldPromotionMsgs() {
  var mySearch = "older_than:180d category:promotions -from:me -confirmation -account -license -registrar -registration -'serial number'";// add promotion msgs to the list
  var batchSize = 100; // Process up to 100 threads at once
  while (GmailApp.search(mySearch, 0, 1).length == 1)
  {
    GmailApp.moveThreadsToTrash(GmailApp.search(mySearch, 0, batchSize));
  }  
  GmailApp.sendEmail("[email protected]", "deleteOldPromotionMsgs function executed", " ");

I'm having a hard time finding out what is actually failing. Is there another way to re-establish or validate 'Authorization' other than by running each function? Any suggestions?

Thanks,

Mike

Upvotes: 1

Views: 182

Answers (1)

Spencer Easton
Spencer Easton

Reputation: 5782

From the Google Cloud Status Dashboard last week:

"No change to report from the last update. We're still actively working to resolve issues with Identity/Authentication. Future updates will follow when there is significant progress to report.

To summarize; some long-lived OAuth tokens have inadvertently been invalidated. "

Imyself had to reauthorize several of my long running scripts.

Upvotes: 2

Related Questions