簡體   English   中英

Google 日歷 API:403 超出日歷使用限制

[英]Google Calendar API: 403 Calendar Usage Limits Exceeded

我使用 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 天內很多嗎?

當我被授權使用谷歌日歷 API 時,我遇到了同樣的錯誤,例如 myuser@gmail.com,然后我試圖添加相同的用戶 (myuser@gmail.com) 作為與會者。

當我添加除 myuser@gmail.com 之外的任何其他與會者時,它起作用了。

這可以解釋為什么有時您會收到錯誤,有時不會。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM