This code has been working for 15 years... every once-in-awhile Google changes something to screw it up.
This time, it seems they deleted/converted a template at sites.google.com that was being used by my spreadsheet form to generate an email (I grab the HTML, do a replacement of some of the key fields, then send an email). When the user hits "submit" on the spreadsheet form, the trigger calls a script.
The old code that fetched the HTML template looked like:
var site = SitesApp.getSiteByUrl(<url>);
var page = site.getChildByName('receipt');
var content = page.getHtmlContent();
I go to "sites.google.com" and it says it deleted all my old forms and converted them to new (all screwed-up in the conversion, buut, hey, it's our Google overlords). I publish what it converted and get the error about permissions, and I see all those "SitesApp" routines are depreciated so now try:
var response = UrlFetchApp.fetch(<new URL>);
var content = response.getContentText();
...and get the error: "Exception: You do not have permission to call UrlFetchApp.fetch. Required permissions: https://www.googleapis.com/auth/script.external_request"
My project already shows that permission, but I follow some rules that expose a JSON script where I make the OAuth scopes explicit:
{
"oauthScopes": [
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/script.send_mail",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/calendar"
],
"timeZone": "America/Adak",
"dependencies": {},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
}
But, still get the error. I see other folks with a similar error, but only when their triggers are implicit, mine is explicitly called out.
As noted above, I changed the code to use UrlFetchApp.fetch after saving the new templates at sites.google.com and point at the new templates at sites..., explicitly defining the appscript.json. I've also tried putting the URL on a publicly available site.
The trigger needed to be deleted and re-added.
Nothing was wrong with the way the trigger was setup... it just needed to be deleted and resetup, then it prompted for the oauth questions again... which it had done the first time it was setup (a long time ago).
So the fact that it required a form entry to be the trigger was the issue that kept it from getting whatever reauthorization it needed after sites.google.com was defunct/depricated.