python-3.x - 通过 python Calendar API 添加与会者时超出日历使用限制
问题描述
我有一个使用谷歌日历 API 的服务器。但是今天我有一个问题。
<HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/9rmkucj5624ove5oe3dvlcchb8%40group.calendar.google.com/events/ilrgnanahon2scuq2hv9u6fcmg?alt=json returned "Calendar usage limits exceeded.">
json
{
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"errors": [
{
"message": "The request is missing a valid API key.",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
但是如果我使用 API 来创建事件、编辑事件,API 就起作用了!我添加与会者的功能
def update_event_employee_email(service, calendarId, eventId, employee_email,displayName):
# First retrieve the event from the API.
event = service.events().get(calendarId=calendarId, eventId=eventId).execute()
#print(event)
add_attendees = {
"displayName": str(displayName),
"email": str(employee_email)
}
try:
current_attendees = event['attendees']
except Exception as e:
current_attendees=[]
if current_attendees:
attendees = event['attendees']
attendees.append(add_attendees)
body = {
"attendees": attendees
}
print(attendees)
else:
body = {
"attendees": [
{
"displayName": str(displayName),
"email": str(employee_email)
}
]
}
#print(event)
try:
event = service.events().patch(calendarId=calendarId, eventId=eventId, body=body).execute()
print(event)
status = 200
except Exception as e:
print(json.loads(e.content)['error']['code'])
status = 400
return status
我还检查了谷歌支持 避免日历使用限制
而且我认为我的 API 没有超出限制
我更新:我的服务构建代码
# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/calendar']
def service_build():
"""Shows basic usage of the Google Calendar API.
Prints the start and name of the next 10 events on the user's calendar.
"""
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
print(os.path.exists('token.pickle'))
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
service = build('calendar', 'v3', credentials=creds)
return service
# Call the Calendar API
所以我想我的问题 例如:如果你有一个新的令牌,你可以发送任何一个 *. 50 场活动,有 100 位客人 - 每个活动有 2 位客人 *。25 场有 100 位宾客的活动 - 每个活动有 4 位宾客
每个限制
天数:36 位客人
周:252 位客人
月:~1080 位客人
所以我也想知道,如何购买更多的限制来增加更多的客人
解决方案
您在避免日历使用限制下列出的配额是指谷歌日历的一般用法,如果您使用的是与 UI 相对的 API),则配额限制更严格。
Google 没有提供有关通过 Calendar API 使用添加与会者的最大配额的确切信息,可用信息是Google Calendar API 使用限制:
Google Calendar API 有每天 1,000,000 次查询的礼貌限制。
要查看或更改项目的使用限制,或请求增加配额,请执行以下操作:
- 如果您的项目还没有结算帐号,请创建一个。
- 访问 API 控制台中 API 库的已启用 API 页面,然后从列表中选择一个 API。
- 要查看和更改与配额相关的设置,请选择配额。要查看使用情况统计信息,请选择使用情况。
换言之,您或许可以免费申请额外配额,但如果您已将配额增加到最大限额,您将无法获得更多配额 - 甚至付费。
现在到您的第二条错误消息:
The request is missing a valid API key
这听起来像是您的身份验证存在一些问题,并且 API 假定您正在尝试使用 API 密钥而不是有效的访问令牌进行身份验证。要丢弃代码实现问题,请测试您的Events: insert或Events:patch请求Try this API
。
推荐阅读
- java - 为什么 Java 比实时卡萨布兰卡晚一个小时?
- bootstrap-modal - 显示模态的引导按钮必须多次单击才能打开模态
- c# - 在 C# 中的线程之间共享本地集合
- html - Bootstrap 4 字体大小 em 在 Mozilla Firefox 和 Google Chrome 中不同
- android - 出现错误 - 运行本机反应时无法识别的命令“run-android”,
- c# - 问题反序列化来自 Wikipedia API 的 JSON 响应
- linux - 用于获取特定用户 ID 和进程计数的 Bash 脚本
- python - Cython 用 setup.py build_clib 包装 c lib
- android - 如果 RealmResults 查询中的条件匹配,如何跳过对象
- docker - 如何在 kubernetes 中挂载包含文件的文件夹