[英]403 Calendar Usage Limits Exceeded on Google Calendar API
我使用 Python 構建了一個應用程序,並將其連接到谷歌日歷 API。
我不明白為什么會收到此錯誤“Google Calendar API: 403 Calendar Usage Limits Exceeded Using Service Account”
我幾乎沒有添加事件,一周可能有 300 個。
我以前有一個舊帳戶,幾天內就增加了數千。 現在,有了這個新的免費帳戶,它給了我這個錯誤!
我能做些什么? 可以修嗎?!
啟動日歷服務:
def initiate_calendar_service():
"""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.
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
添加事件:
for i in range(1):
startStrip = datetime.datetime.strptime(event_start, "%Y-%m-%dT%H:%M:%S")
endStrip = datetime.datetime.strptime(event_end, "%Y-%m-%dT%H:%M:%S")
dayOfWeek = startStrip + datetime.timedelta(days=i)
# les bons formats
currentStart = str(startStrip + datetime.timedelta(days=i)).replace(" ", "T")
currentEnd = str(endStrip + datetime.timedelta(days=i)).replace(" ", "T")
calendarEnd = str(endStrip + datetime.timedelta(days=i + 1)).replace(" ", "T")
events_result = service.events().list(calendarId='primary', timeMin=currentStart + "-00:00",
maxResults=30, timeMax=calendarEnd + "-00:00",
singleEvents=True, orderBy='startTime').execute()
events = events_result.get('items', [])
currentEmployees = []
for event in events:
currentEmployees.append(event['summary'])
if employee in currentEmployees:
event_done = False
event['summary'] = employee
for event in events:
if str2datetime(currentStart) <= str2datetime(event['end']['dateTime'].split('+')[0]) and str2datetime(currentEnd) >= str2datetime(event['start']['dateTime'].split('+')[0]):
event_done = False
print(employee + ' est occupé')
break
else:
event_done = True
break
if employee not in currentEmployees:
event_done = True
if event_done:
option = show_message_box(QMessageBox.Critical,
"Confirmation",
"Voulez-vous bloquer cette plage horraire?"\
"L'employé : \"" + employee + "\" sera marqué comme indisponible en raison de : " + reason, \
"Nom de l'employé: " + employee + "\n" \
"Raison: " + reason + "\n" \
"À partir du : " + currentStart + "\n" \
"À ce jour " + currentEnd + "\n"
)
if option == QMessageBox.Yes:
event_done = True
else:
print("Événement ignoré!")
event_done = False
break
if event_done:
event = {
'summary': employee,
'location': location,
'description': reason,
'start': {
'dateTime': currentStart,
'timeZone': 'America/New_York',
},
'end': {
'dateTime': currentEnd,
'timeZone': 'America/New_York',
},
'attendees': [
{'email': event_email},
],
'reminders': {
'useDefault': True,
},
}
register_event(service, event)
else:
second_message_box(QMessageBox.Critical,
"ATTENTION!",
"L'inspecteur " + employee + " est déjà occupé à ce moment-là.""\n" \
"Veuillez essayer une autre plage horraire.", QMessageBox.Ok)
附加信息:
我有一個帳戶,在 1 個月內,我做了 3041 個 calendar.events.list 請求。 和 181 個日歷.事件.插入。
我沒有問題。
這一次,使用一個新帳戶,在 2 天內,我做了 730 個 calendar.events.list 請求和 175 個 calendar.events.insert。 175 事件插入在 2 天內很多嗎?
這是給我錯誤的帳戶:
Calendar usage limits exceeded
的文檔中看到:用戶達到了 Google 日歷限制之一,以保護 Google 用戶和基礎設施免受濫用行為。
此處列出了限制,重要的是
對於 G Suite 免費版和 G Suite 試用帳戶,限制低於上述限制。
和
免費試用期結束時,如果您的域累計計費至少為 30 美元(或等值),日歷使用限制會自動增加。
因此,基本上,如果您有一個新帳戶並且仍處於試用期,那么您的限制低於試用限制后的限制(Google 未指定確切的限制),這就是您在新帳戶中遇到此問題的原因。
除了“為測試發送垃圾郵件”通常不是一個很好的做法並且會引起對“濫用行為”的懷疑之外,對外部訪客的限制更嚴格,因此出於測試目的,您應該邀請您自己域中的用戶的外部。
為了避免命中限制,還建議使用指數退避來降低請求的速度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.