调用Gmail插件getAttachments()权限报错及所需权限咨询
解决Gmail插件调用
getAttachments()的权限报错问题 这个权限报错我之前帮人排查过好几次,问题很明确:你当前配置的OAuth权限范围里,没有获取邮件附件所需的权限。
要成功调用message.getAttachments(),你需要在appscripts.json的oauthScopes数组中添加 https://www.googleapis.com/auth/gmail.addons.current.message.readonly 这个权限。
为什么现有权限不够?
你现在用的gmail.addons.current.message.metadata只能获取邮件的元数据(比如主题、发件人、时间这类基础信息),完全碰不到邮件正文和附件;而gmail.addons.execute、gmail.addons.current.message.action这些权限只负责插件的执行逻辑和消息动作触发,和内容读取完全不相关。
更新后的权限配置示例
调整后的oauthScopes大概是这样:
"oauthScopes": [ "https://www.googleapis.com/auth/gmail.addons.execute", "https://www.googleapis.com/auth/gmail.addons.current.message.metadata", "https://www.googleapis.com/auth/gmail.addons.current.message.action", "https://www.googleapis.com/auth/script.external_request", "https://www.googleapis.com/auth/gmail.addons.current.message.readonly" ]
最后提醒两点
- 加完权限后,一定要重新部署你的Gmail插件,并且让使用插件的用户重新授权一次,新的权限才能生效;
- 遵循最小权限原则就好,
readonly权限已经足够读取附件,没必要申请更宽泛的全邮件访问权限。
内容的提问来源于stack exchange,提问作者Glen Little
相关产品推荐
相关产品推荐

