0

I am using google calendar api with python. I have created a service account, and am using the private key to connect to the calendar api from my server.

Everything was working fine.

Yesterday I started getting the error:

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
 }
}

When I log into the console my limits are:

Daily quotas reset at midnight Pacific Time (PT).

Queries

requests/day 114 of 1,000,000
requests/100seconds/user 500

The console correctly shows me that I am hitting 4XX errors and each hit increments the error count, but I am not sure how to fix this

Does anyone have some idea where I could start looking?

Below my code I use to connect

with open(os.path.dirname(os.path.abspath(__file__)) + "/KeyName.p12") as f:
        private_key = f.read()

        credentials = SignedJwtAssertionCredentials(client_email, private_key,
                scope=['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.readonly'])

        http = Http()
        credentials.authorize(http)
        service = build(serviceName='calendar', version='v3', http=http)

        today_beginning = datetime.combine(date.today(), time())
        today_end = today_beginning + timedelta(1, 0) - timedelta(0, 1)

        now = datetime.now().isoformat()
        timeMin = today_beginning.isoformat() + 'Z'
        timeMax = today_end.isoformat() + 'Z'

        # events
        events = service.events().list(calendarId=calendar_id, timeMin=timeMin, timeMax=timeMax).execute() 

At this stage it break with

raise HttpError(resp, content, uri=self.uri) googleapiclient.errors.HttpError: https://www.googleapis.com/calendar/v3/calendars/.../hidden/parts/.. returned "Not Found">

Below is an image showing my requests over the last 30 days, you'll see where to 200 drop and the 4xx begin

Google API requests graph

UPDATE: I have made some changes with limited success

I changed the code to the following

scopes = ['https://www.googleapis.com/auth/calendar.readonly']
# p12 keyfile
# keyfile = os.path.dirname(os.path.abspath(__file__)) + "/" + p12_key
# credentials = ServiceAccountCredentials.from_p12_keyfile(client_email, keyfile, 'notasecret', scopes)

# json keyfile
keyfile = os.path.dirname(os.path.abspath(__file__)) + "/" + json_key
credentials = ServiceAccountCredentials.from_json_keyfile_name(keyfile, scopes)

http_auth = credentials.authorize(Http())
service = build(serviceName='calendar', version='v3', http=http_auth)

today_beginning = datetime.combine(date.today(), time())
today_end = today_beginning + timedelta(1, 0) - timedelta(0, 1)

now = datetime.now().isoformat()
timeMin = today_beginning.isoformat() + 'Z'
timeMax = today_end.isoformat() + 'Z'

# events
events = service.events().list(calendarId=calendar_id, timeMin=timeMin, timeMax=timeMax).execute()

This code reflects the latest changes from the documentation

I tried to authenticate by using json & a p12 cert

The error still persisted. I created another service account, with new credentials, json+p12 and the error still persisted. I created new calendars, the error persisted.

I then created a service account on another google account that I have, recreated the calendars, and created new credentials for this service account. That made it work again.

This makes me think that there is something going on with the accounts?

The account where the error occurs is a paid for google apps for business account. I will log a ticket with that account and report back

user7673
  • 1
  • 1

2 Answers2

0

You can see in this documentation, the same error that you encountered. The suggested action is directed to this page.

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

If you have enabled billing for your project, you can see the quota percentage for each API. You can view and change quotas from the API section's API Library and Enabled APIs links. Selecting an API from the API Library list or from the Enabled APIs page takes you to a page with overview, usage, and quota links for that API. Choosing Quotas lets you view and change quota-related settings. Choosing Usage provides you with usage statistics as well as response code and method information.

Try to follow the first part of the answer here, about the Google APIs console project.

Also check this issue about INTEGRATION WITH GOOGLE CALENDAR API.

Community
  • 1
  • 1
KENdi
  • 7,576
  • 2
  • 16
  • 31
0

After analysing logs, I found

Below Limits for Create

Free Google Apps Account For a user: Initially: 100 Extenal Guests Domains Emails limit Accumulative: 1 External Guest for 40 Minutes

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

Where Purchased GSuite Calendar API gives initial limit of 1000 Guest Request

https://github.com/manjeshpv/gsuite-google-calendar-api-limits

Manjesh V
  • 1,230
  • 15
  • 22