python - Google API(gmail 和电子表格): what more should I set up, 或者知道我缺少什么设置?

标签 python google-apps-script gmail-api google-sheets-api

我正在创建一个网络应用程序,其中包括一些 cron 作业,这些作业将调用 gmail API 和 Google 电子表格 API。

我已经在我的 Google 开发人员 deashboard 中创建了一个项目及其凭据,以便与我的应用程序一起使用。

我还在控制台中启用了 Gmail APIGoogle Sheets API

我正在使用 Python 库,并且调用这两个 API 均失败。

例如,电子表格服务会抛出此错误:

/home/vardelean/work/connect-app/ty/connect/commands/populate_matching_spreadsheet.pyc in iterate_google_spreadsheet(document_id, spreadsheet_service)
    300         unmatched_hotels_document = spreadsheet_service.values().get(
    301                         spreadsheetId=document_id,
--> 302                         range='Sheet1'
    303         ).execute()["values"]
    304                 header = unmatched_hotels_document[0]

/home/vardelean/ve/connect/local/lib/python2.7/site-packages/oauth2client/util.pyc in positional_wrapper(*args, **kwargs)
    135                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
    136                     logger.warning(message)
--> 137             return wrapped(*args, **kwargs)
    138         return positional_wrapper
    139 

/home/vardelean/ve/connect/local/lib/python2.7/site-packages/googleapiclient/http.pyc in execute(self, http, num_retries)
    830       callback(resp)
    831     if resp.status >= 300:
--> 832       raise HttpError(resp, content, uri=self.uri)
    833     return self.postproc(resp, content)
    834 

HttpError: <HttpError 403 when requesting https://sheets.googleapis.com/v4/spreadsheets/...document id here...../values/Sheet1?alt=json returned "The caller does not have permission">

我不知道缺乏权限意味着什么。我尝试以该用户身份登录时访问该文件,并且我确实拥有该文件的编辑权限。如前所述,我还启用了 Google 电子表格 API。

还有 Gmail 服务:

File "/home/vardelean/work/connect-app/ty/connect/commands/vwh_test_google_apis.py", line 31, in <module>
    main()
  File "/home/vardelean/work/connect-app/ty/connect/commands/vwh_test_google_apis.py", line 23, in main
    for message_meta in message_list.execute().get('messages', []):
  File "/home/vardelean/ve/connect/local/lib/python2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/vardelean/ve/connect/local/lib/python2.7/site-packages/googleapiclient/http.py", line 832, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/gmail/v1/users/me/messages?labelIds=INBOX&alt=json returned "Mail service not enabled">

...我不知道“邮件服务未启用”是什么意思,因为我确实在开发控制台中启用了它。

此外,我还检查了使用空凭据文件(例如)会出现什么错误,至少对于 gmail 服务来说,这是一些其他错误,因此凭据在某种程度上必须是好的。该错误是RuntimeError:无法使用存储在//path/to/bad/credentials/file 的凭据进行授权

谁能帮忙解决这个问题吗?

最佳答案

您可能想尝试设置 isMailboxSetuptrue,如本 thread 中所述并在此评论SO post .

如给定的 reference 中所述:

isMailboxSetup indicates if the user's Google mailbox is created. This property is only applicable if the user has been assigned a Gmail license.

关于python - Google API(gmail 和电子表格): what more should I set up, 或者知道我缺少什么设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41854878/

相关文章:

javascript - 对使用 Google 电子表格维护/更新 Google 日历(包括自动更改颜色)的脚本进行故障排除

python - Conda 更新错误 : `conda.core.link:_execute(637): An error occurred while installing package ' None'. AssertionError()`

python - Sklearn.KMeans() : Get class centroid labels and reference to a dataset

Python3——突破包罗万象的 try block

oauth-2.0 - Gmail API google.auth.exceptions.RefreshError 范围无效

c# - 谷歌API : Gmail Service Push Notification (Watch) - User not authorized to perform this action

r - 如何使用 R 从 gmail 下载附件?

jquery - 如何转义 JSON 字符串中的 unicode 语法 (u'foo')?

google-apps-script - 要使用 google apps 脚本将单元格文本和评论复制到另一个工作表?

google-apps-script - Adsense 报告 Google 表格