Here's the function in question:
function GetResponseDate(confirmation) {
var threads = GmailApp.search(confirmation);
var initialResponse;
if(threads.length!=0){
initialResponse = threads[0].getMessages()[0].getDate();
}
else{
initialResponse = "none";
}
return initialResponse;
}
Here's the manifest:
{
"oauthScopes":[
"https://www.googleapis.com/auth/gmail.readonly",
"https://www.googleapis.com/auth/gmail.addons.current.message.readonly",
"https://www.googleapis.com/auth/gmail.addons.current.message.action",
"https://www.googleapis.com/auth/gmail.modify"
],
"timeZone": "America/Los_Angeles",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER"
}
The implementation is just
= GetResponseDate("12345")
within a cell.
I've granted all of the permissions requests that have popped up (whether by default, or the additional ones I added in the manifest file), but I still get the sheets error:
The script does not have permission to perform that action. Required permissions: (https://www.googleapis.com/auth/gmail.readonly || https://www.googleapis.com/auth/gmail.addons.current.message.readonly || https://www.googleapis.com/auth/gmail.addons.current.message.action || https://www.googleapis.com/auth/gmail.modify || https://mail.google.com/) (line 3).
Answered by Alan Wells and Tanaike (though I can't upvote them because my account is new).
Solution is: individual cell formulas can't request permissions, and the correct permission to request is
https://mail.google.com/
. One workaround is: execute script as a menu item instead of within a cell (though it needs to be modified to interpret and output to cells).