1
votes

I have a server use google calendar API. But today i have a problem.

 <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/9rmkucj5624ove5oe3dvlcchb8%40group.calendar.google.com/events/ilrgnanahon2scuq2hv9u6fcmg?alt=json returned "Calendar usage limits exceeded.">

The json

{
  "error": {
    "code": 403,
    "message": "The request is missing a valid API key.",
    "errors": [
      {
        "message": "The request is missing a valid API key.",
        "domain": "global",
        "reason": "forbidden"
      }
    ],
    "status": "PERMISSION_DENIED"
  }
}

But if i use API to creat events, edit events, API worked! My function to add attendee

def update_event_employee_email(service, calendarId, eventId, employee_email,displayName):
    # First retrieve the event from the API.
    event = service.events().get(calendarId=calendarId, eventId=eventId).execute()
    #print(event)
    add_attendees = {
        "displayName": str(displayName),
        "email": str(employee_email)
        }
    try:
        current_attendees = event['attendees']
    except Exception as e:
        current_attendees=[]
    if current_attendees:
        attendees = event['attendees']
        attendees.append(add_attendees)
        body = {
            "attendees": attendees
        }
        print(attendees)
    else:
        body = {
              "attendees": [
                {
                    "displayName": str(displayName),
                    "email": str(employee_email)
                }
              ]
            }
    #print(event)
    try:
        event = service.events().patch(calendarId=calendarId, eventId=eventId, body=body).execute()
        print(event)
        status = 200
    except Exception as e:
        print(json.loads(e.content)['error']['code'])
        status = 400
    return status

I also check the google support Avoid Calendar use limits

And i think my API doesnt over limit

Send too many invitations to external guests

I update: My service build code

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


def service_build():
    """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.
    print(os.path.exists('token.pickle'))
    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
    # Call the Calendar API

So i guess my problem Ex: If you have a fresh token you can send any one *. 50 Events having 100 guest - 2 Guests per event *. 25 Events having 100 guest - 4 Guests per event

Limits per

Day: 36 Guests

Week: 252 Guests

Month: ~1080 Guests

So i also want to know, how to buy more limit to add more Guests

1
please include your authorization code where is service created.DaImTo
thank you, i already updated, but when i creat new events, change time of events, ... etc, it is ok, but when i add attendee, problem comeLinh Nguyễn Ngọc

1 Answers

0
votes

The quota you list under Avoid Calendar use limits refers to the general usage of Google Calendar, if you are using the API opposed to UI), the quota limits are stricter.

Google does not provide exact information on the maximum quota for adding attendees via Calendar API usage, the available information is Google Calendar API Usage Limits:

The Google Calendar API has a courtesy limit of 1,000,000 queries per day.

To view or change usage limits for your project, or to request an increase to your quota, do the following:

  1. If you don't already have a billing account for your project, then create one.
  2. Visit the Enabled APIs page of the API library in the API Console, and select an API from the list.
  3. To view and change quota-related settings, select Quotas. To view usage statistics, select Usage.

In other words, you might be able to request extra quota for free, however, if you already increased the quota to the maximum allowance, you will not be able to obtain more quota - even paying.

Now to your second error message:

The request is missing a valid API key

This sounds like there is some problem with your authentication and the API assumes that you are trying to authenticate with an API key instead of a valid access token. To discard code implementation issues test your Events: insert or Events:patch request with the Try this API.