故障排除:Google Calendar Insert API 错误“权限不足:请求的身份验证范围不足”

Rah*_*ade 8 google-api google-api-client

为了测试我们的应用程序,我需要插入/更新谷歌日历事件并验证边缘情况,比如会议邀请是否超过 30 天,它不应该显示给最终用户。我正在为单个 gmail id testaccount@.com 进行此设置,并尝试操纵事件以涵盖所有边缘情况。

按照此链接 - https://developers.google.com/calendar/v3/reference/events/insert

1)我创建了一个新项目https://console.cloud.google.com

2) 启用谷歌日历 API

3)为credentials.json设置OAuth客户端

4) 运行 python 快速启动以获得 10 个日历事件 - 验证步骤 3 是否正确。

5)现在在同意屏幕上插入添加以下范围的事件 https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/calendar.events

6) 重新生成凭证,使其具有新添加的插入事件的范围。

我收到以下错误消息 - 请求https://www.googleapis.com/calendar/v3/calendars/primary/events?alt=json时出现 HttpError 403返回“权限不足:请求的身份验证范围不足”。

我也尝试过使用电子邮件 ID 代替“primay”,但最终还是出现了同样的错误。

小智 16

我遇到了同样的问题(=错误消息)。在演示软件的顶部查看以下几行:

# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']
Run Code Online (Sandbox Code Playgroud)

并修改为

# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/calendar']
Run Code Online (Sandbox Code Playgroud)

然后删除您的 token.pickle 文件,然后重新运行您的脚本。