我最近将 python Web 应用程序部署到了利用 Google 日历 API 的 Heroku 平台。我能够使用OAuth 2.0凭据从日历中获取事件列表,但在这种情况下通常不需要 Web 应用程序域验证。相反,推送通知功能需要域验证和发送到 Google API 的 HTTPS 请求才能激活它。
当我尝试使用带有代码的监视方法执行 HTTPS 请求时:
body={
"id": "<specified_uuid_read_from_file>",
"type": "web_hook",
"address": "https://<heroku_application_id>.herokuapp.com"
}
events_result = service.events().watch(calendarId="primary", body=body).execute()
我得到这个回应:
googleapiclient.errors.HttpError: <HttpError 401 when requesting https://www.googleapis.com/calendar/v3/calendars/primary/events/watch?alt=json returned "Unauthorized WebHook callback channel: https://<heroku_application_id>.herokuapp.com">
我已经做了:
- 通过 Google Search Console 通过上传 html 文件验证域https://<heroku_application_id>.herokuapp.com 。
- 将此域添加到 Google Api“域验证”选项卡。
我想知道除了不适当的 Google 授权过程导致的域验证问题之外,还有什么其他可能的原因以及如何解决?
先感谢您。
编辑: 最终我能够通过更新 Google API 凭据来获得访问权限。目前一切正常。尽管如此,我仍然无法解释导致此错误的实际问题。