Search code examples
pythongoogle-apigoogle-calendar-apigoogle-oauth

Google Calendar API -- "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup"


I'm trying to write some Python code that creates a calendar (within my own account) and adds events to it.

I keep on getting the following 403 error:

Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup

This does not happen when I create new calendars:

created_calendar = service.calendars().insert(body=calendar).execute()

But the error does come up when I try and create events within the calendar I just made:

event = service.events().insert(calendarId=created_calendar, body=event).execute()

As per other help threads, I've made all of the correct authentications (API key, OAuth, Service Account):

enter image description here

And my daily limit is way beyond the number of requests I've been sending:

enter image description here

I am specifying the OAuth credentials.json file when creating my api client. I am pointing the GOOGLE_APPLICATION_CREDENTIALS environment variable at the service account key (also json) before running.

I'm not sure how else I can authenticate myself...some help would really be appreciated!

EDIT

This is my script (and I believe a minimal example of the error) in case it's helpful:

import datetime
import pytz
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

# If modifying these scopes, delete the file token.pickle.
# Add .readonly for read only
SCOPES = ['https://www.googleapis.com/auth/calendar']


def build_cal_service():
    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

def main():
    service = build_cal_service()

    calendar = {
        'summary': 'TEST CAL',
        'timeZone': 'America/Los_Angeles'
    }

    created_calendar = service.calendars().insert(body=calendar).execute()

    time = datetime.datetime(
        year=2019,
        month=11,
        day=9,
        hour=21,
        tzinfo=pytz.timezone('US/Pacific'))

    event = {
      'summary': 'test summary',
      'description': 'test description.',
      'start': {
        'dateTime': time.isoformat(),
      },
      'end': {
        'dateTime': (time + datetime.timedelta(hours=1)).isoformat(),
      },
      'attendees': [
        {'email': '[email protected]'},
        {'email': '[email protected]'},
      ],
    }

    event = service.events().insert(calendarId=created_calendar, body=event).execute()

Solution

  • How about this modification?

    Unfortunately, in my environment, when I tested your provided script, I couldn't confirm the error of Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup. But I think that in your script, event = service.events().insert(calendarId=created_calendar, body=event).execute() occurs an error. So how about the following modification?

    From:

    event = service.events().insert(calendarId=created_calendar, body=event).execute()
    

    To:

    event = service.events().insert(calendarId=created_calendar['id'], body=event).execute()
    

    Note:

    • created_calendar of created_calendar = service.calendars().insert(body=calendar).execute() is an object. So when the calendar ID is retrieved, please use created_calendar['id'].
    • This answer supposes that credentials.json is the file which was downloaded by "Create credentials" at "OAuth client ID".
    • If the error related to the authorization occurs, please delete the file of token.pickle and run the script, and then authorize again.

    References: