【发布时间】:2020-06-22 21:30:10
【问题描述】:
我使用 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 个 calendar.events.insert。
我没问题。
这一次,使用新帐户,我在 2 天内完成了 730 个 calendar.events.list 请求和 175 个 calendar.events.insert。 2天内175个事件插入是不是很多??
这是给我错误的帐户:
【问题讨论】:
标签: python google-api google-calendar-api google-api-python-client