调用方在使用 GMail API 时没有权限错误



我在运行在Google App Engine上的django网站上收到500服务器错误。当我查看Google App Engine日志时,我看到以下错误:

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest returned "The caller does not have permission">

当我硬刷新浏览器时,此错误消失了。然后过了一段时间,它又弹出了。发生在手机(火狐,野生动物园(,笔记本电脑(火狐,铬

(。更新:

在 Django settings.py 中,我有以下代码。它的最后一行生成错误:

pickle_path = 'token.pickle'  # path to token.pickle
with open(pickle_path, 'rb') as token:
creds = pickle.load(token)
SERVICE = build('gmail', 'v1', credentials=creds)  # ERROR LINE

当我在本地运行 django 服务器时:我收到以下错误:

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest returned "The caller does not have permission">

当我从终端重新启动云SQL连接时 - 错误消失了。直到几天前,这种情况才发生过。

这是一个解决方法:

  • 直接从谷歌下载discovery_doc
  • 这里
  • 加载 json 文件(您可以将其命名为gmail-api.json(
  • 使用build_from_document从此 json 文件构建

以前

from googleapiclient.discovery import build
gmail_creds = get_service_account_creds()
gmail_service = build('gmail', 'v1', credentials=gmail_creds)

from googleapiclient.discovery import build_from_document
discovery_doc = load_json('config/gmail-api.json')
gmail_creds = get_service_account_creds()
gmail_service = build_from_document(discovery_doc, credentials=gmail_creds)

看来它现在是谷歌的P0,所以希望它能很快得到修复。

https://issuetracker.google.com/issues/160441983

我也开始面临这个问题。我已经使用谷歌API一年多了,但是突然这个错误HttpError 403 when requesting https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest returned "The caller does not have permission了。但是,有几次我没有看到此错误,并且 API 调用成功。我希望这个错误在Gmail API服务器上。

更新: 我可以毫无问题地调用谷歌API。似乎问题在谷歌结束时得到解决。

我在使用 GAM ADV-X 时遇到了同样的问题。我认为这是我的计算机上的问题,所以我在 2 台不同的计算机上尝试并得到相同的错误。周末看起来Gmail API确实发生了变化。将向谷歌提交票证。

最新更新