我正在尝试使用 Gmail 插件访问 Gmail 中的所有草稿,但它会记录这样的错误
Access denied: : Missing access token for per message scope authorization. [line: 8, function: buildAddon, file: Code]
我的 onTrigger 函数看起来像这样
function buildAddon(e) {
var cards = [];
var accessToken = e.messageMetadata.accessToken;
GmailApp.setCurrentMessageAccessToken(accessToken);
var draftMessages = GmailApp.getDraftMessages();
for (var i = 0; i < draftMessages.length; i++) {
cards.push(CardService.newCardBuilder()
.setHeader(CardService.newCardHeader()
.setTitle(draftMessages[i].getBody())).build());
}
return cards;
}
清单json
文件看起来像这样
{
"oauthScopes": [
"https://www.googleapis.com/auth/gmail.readonly",
"https://www.googleapis.com/auth/gmail.addons.execute",
"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/gmail.addons.current.message.readonly",
"https://www.googleapis.com/auth/gmail.addons.current.action.compose"
],
"gmail": {
"contextualTriggers": [
{
"unconditional": {},
"onTriggerFunction": "buildAddon"
}
],
"logoUrl": "https://www.gstatic.com/images/icons/material/system/2x/bookmark_black_24dp.png",
"name": "Draft reminder",
"version": "TRUSTED_TESTER_V2"
}
}