无法通过Gmail附加组件访问Gmail草稿

时间:2017-11-10 14:39:07

标签: google-apps-script gmail gmail-addons

我正在尝试使用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"
}
}

1 个答案:

答案 0 :(得分:3)

您错过了草稿权限的范围。

https://www.googleapis.com/auth/gmail.compose 管理草稿并发送电子邮件“

以下是范围的参考: https://developers.google.com/identity/protocols/googlescopes#gmailv1