You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用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"
]

最后提醒两点

  1. 加完权限后,一定要重新部署你的Gmail插件,并且让使用插件的用户重新授权一次,新的权限才能生效;
  2. 遵循最小权限原则就好,readonly权限已经足够读取附件,没必要申请更宽泛的全邮件访问权限。

内容的提问来源于stack exchange,提问作者Glen Little

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:52:21