我正在尝试使用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"
}
}
答案 0 :(得分:3)
您错过了草稿权限的范围。
“https://www.googleapis.com/auth/gmail.compose 管理草稿并发送电子邮件“
以下是范围的参考: https://developers.google.com/identity/protocols/googlescopes#gmailv1