gpt4 book ai didi

python - 谷歌日历 API : 403 Calendar Usage Limits Exceeded

转载 作者:行者123 更新时间:2023-12-04 13:35:16 27 4
gpt4 key购买 nike

我使用 Python 构建了一个应用程序并将其连接到谷歌日历 API。

我不明白为什么会收到此错误“Google Calendar API:403 使用服务帐户超出日历使用限制”

我几乎没有添加事件,一周大概 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个事件插入是不是很多??

最佳答案

当我被授权使用 Google Calendar API 时,我遇到了同样的错误,例如 myuser@gmail.com,然后我试图将相同的用户 (myuser@gmail.com) 添加为与会者。

当我添加除 myuser@gmail.com 之外的任何其他与会者时,它起作用了。

这可以解释为什么有时会出现错误,有时却不会。

关于python - 谷歌日历 API : 403 Calendar Usage Limits Exceeded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62508640/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com