【问题标题】:Google Calendar API: 403 Calendar Usage Limits ExceededGoogle 日历 API:超出 403 日历使用限制
【发布时间】:2020-10-11 23:21:12
【问题描述】:

我使用 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个事件插入很多吗??

【问题讨论】:

  • 每个活动有多少人参加?这也会影响事物。
  • 只有 1 个 @DaImTo !!此外,maxResults 被错误地设置为 300。即使我没有那么多。我的日历中每天最多有 10 个事件。你认为这是问题吗?我会永远收到这条消息吗?大声笑
  • 最大行数不应影响这一点
  • 请编辑您的问题并包含您的代码。
  • 我的代码有 200 多行...@DaImTo

标签: python google-api google-calendar-api google-api-python-client


【解决方案1】:

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

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

这可以解释为什么有时您会收到错误,有时不会。

【讨论】:

  • 此外,我观察到与发送邀请数量相关的配额对我的帐户来说比文档声称的要严格得多。即使我使用付费的 Google Workspace 帐户。在向同一用户发送了大约 20 个邀请后,我在大约 24 小时内无法再向与会者添加用户电子邮件。
猜你喜欢
  • 1970-01-01
  • 2019-03-27
  • 2012-03-12
  • 2014-12-03
  • 2018-07-29
  • 2015-12-12
  • 2018-01-20
  • 2017-11-24
  • 1970-01-01
相关资源
最近更新 更多