【问题标题】:Google APIs (gmail and spreadsheet): what more should I set up, or to know what setup I'm missing?Google API(gmail 和电子表格):我还应该设置什么,或者知道我缺少什么设置?
【发布时间】:2017-06-10 19:51:26
【问题描述】:

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

我在我的谷歌开发者仪表板中创建了一个项目,并为其创建了凭据,以用于我的应用程序。

我还在控制台中启用了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: Couldn't authorise with the crentials stored at //path/to/bad/credentials/file

有人可以帮忙吗?

【问题讨论】:

    标签: python google-apps-script gmail-api google-spreadsheet-api


    【解决方案1】:

    您可能想尝试将isMailboxSetup 设置为true,如此thread 中所述,并在此SO post 中发表评论。

    如给定的reference 中所述:

    isMailboxSetup 表示是否创建了用户的 Google 邮箱。此属性仅适用于已为用户分配了 Gmail 许可的情况。

    【讨论】:

    • 谢谢!问题不是这样。收件箱是以前创建的,但似乎我创建的凭据不正确。 “凭据”是指私有凭据(我认为它们被称为客户端密码),我将从中创建另一个凭据文件,用于对 API 调用进行身份验证。我还没有弄清楚出了什么问题,但似乎可以创建新的凭据(新的私有凭据或客户端密码以及来自它们的新 api 凭据)。
    猜你喜欢
    • 1970-01-01
    • 2019-05-30
    • 2013-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多