繁体   English   中英

Google Apps 脚本 — 使用 getdraft() 方法不起作用

[英]Google Apps Scripts — Using getdraft() method not working

尝试扩展撰写 UI 以从草稿中获取一些信息,当我尝试使用 draft.getMessage().getBody() 获取草稿时,出现此错误:

Access denied: : Missing access token for authorization. Request: MailboxService.GetMessage. [line: 19, function: validateRecipients, file: Code]

我的代码:

var draft = GmailApp.getDrafts()[0];
var content = draft.getMessage().getBody();
draft.update("blabla@gmail.com", "Disclosure Alert", "The below message is flagged as possible data disclosure.\n Recipients:"+allEmails+"\n Content:\n"+content);
draft.send();

我的清单范围:

  "oauthScopes" : [
    "https://mail.google.com/",
    "https://www.googleapis.com/auth/userinfo.email",
    "https://www.googleapis.com/auth/script.locale",
    "https://www.googleapis.com/auth/script.send_mail",
    "https://www.googleapis.com/auth/script.external_request",
    "https://www.googleapis.com/auth/gmail.metadata",
    "https://www.googleapis.com/auth/gmail.modify",
    "https://www.googleapis.com/auth/gmail.compose",
    "https://www.googleapis.com/auth/gmail.send",
    "https://www.googleapis.com/auth/gmail.addons.current.action.compose", 
    "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.message.action",
    "https://www.googleapis.com/auth/gmail.addons.execute"
    ]

在插件中使用多个范围时,将自动选择最严格的范围(请参阅相关问题: 在 Gmail 插件中,如何访问 GmailApp.search 返回的所有线程的详细信息? )。

Since you are already using the least restrictive GMail scope ( https://mail.google.com/ ) I suggest you change your manifest scopes to the following (Notice removed https://www.googleapis.com/auth/gmail.addons.current.message.*范围):

"oauthScopes" : [
    "https://mail.google.com/",
    "https://www.googleapis.com/auth/userinfo.email",
    "https://www.googleapis.com/auth/script.locale",
    "https://www.googleapis.com/auth/script.external_request",
    "https://www.googleapis.com/auth/gmail.addons.execute"
]

If you consider publishing this add-on, bear in mind that you will not be allowed the https://mail.google.com scope, so you may be interested in checking out other scopes such as https://www.googleapis.com/auth/gmail.readonly

参考

在应用程序脚本文档的每个函数/方法下,您都会获得 Scopes。 对于这个:

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM