【问题标题】:Gmail API "Error 403: Request had insufficient authentication scopes" with Go language使用 Go 语言的 Gmail API“错误 403:请求的身份验证范围不足”
【发布时间】:2021-01-22 16:35:18
【问题描述】:

按照 Go 快速入门说明 here ,启用 Gmail API,下载客户端配置,然后执行 quickstart.go。以下行显示正在请求 GmailSendScope。

config, err := google.ConfigFromJSON(b, gmail.GmailSendScope)

按照其余说明进行操作。保存 token.json 时,程序显示以下消息:

Saving credential file to: token.json
2020/10/07 12:36:13 Unable to retrieve labels: googleapi: Error 403: Request had 
insufficient authentication scopes.
More details:
Reason: insufficientPermissions, Message: Insufficient Permission

在开发者控制台上,我确实看到了用于 Quickstart 项目的 Desktop 类型的 Oauth 客户端,并且安全屏幕确实显示我允许应用程序使用我的 gmail 帐户发送电子邮件。

我不知道如何解决这个问题。

macOS Catalina 10.15.7,go1.15.2 darwin/amd64

谢谢你的帮助!!!

【问题讨论】:

  • 我能问一下你当前的脚本和the script of quickstart的区别吗?
  • 唯一的区别是我上面列出的那一行。原始脚本有 gmail.GmailReadonlyScope。该程序适用于该范围。但是我需要发送电子邮件,因此将范围更改为 gmail.GmailSendScope 并且无法保存 token.json 文件。在按照脚本中的建议运行 GmailSendScope 脚本之前,我删除了 ReadonlyScope 的 token.json 文件。
  • 感谢您的回复。在您的情况下,当使用gmail.MailGoogleComScope 而不是gmail.GmailSendScope 时,您会得到什么结果?在这种情况下,gmail.MailGoogleComScopehttps://mail.google.com/。顺便说一句,当您修改范围时,请删除token.json并重新授权范围。请注意这一点。
  • 是的,做到了。非常感谢,我花了很多时间在这上面。下一步是实际发送电子邮件。再次感谢!!!

标签: go gmail-api


【解决方案1】:

感谢田池。使用gmail.MailGoogleComScope 解决了这个问题!

【讨论】:

    猜你喜欢
    • 2021-10-20
    • 2021-01-04
    • 2016-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2021-12-12
    相关资源
    最近更新 更多