I am creating a Gmail Addon and need to access attachments associated with an email, in the addon. However, I get the following error, when testing the addon :
Exception: Access denied: : Access token does not grant access to the requested thread: msg-f:1709866191276978905
.
I have set the following scopes in oauth:
"oauthScopes": [
"https://www.googleapis.com/auth/gmail.addons.execute",
"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.addons.current.message.metadata",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/userinfo.email"
]
And this is the code snippet:
function startApp(e) {
return getDocsUI(e);
}
function getDocsUI(e){
GmailApp.setCurrentMessageAccessToken(e.messageMetadata.accessToken);
let currentEmail = GmailApp.getThreadById(e.messageMetadata.messageId);
return HtmlService.createHtmlOutput().append(`<div>'Accessing docs'</div>`);
}
I have already tried other variants of this question, that were present on stack-overflow. Please do let me know what I have done wrong.
CodePudding user response:
Two things
eventObject.messageMetadata.accessToken
is deprecated, in the future you should use eventObject.gmail.accessToken instead. Same goes foreventObject.gmail.messageId
instead ofeventObject.messageMetadata.messageId
.message
andthread
are not the same thing. For retrieving a message you should use the methodGmailApp.getMessageById(eventObject.gmail.messageId)
instead ofgetThreadById(eventObject.gmail.messageId)
.