I’m trying to request my google api events list.
I have set everything up and when I send the request, I’m getting the complete list of events, leading me to conclude that I don’t have the right date format for timeMin and timeMax. However, when I use the exact same info in the api explorer, it works as expected…
When I run with q parameter, I get the expected results.
When I run with just the singleEvents and orderBy params (w/o timeMin and timeMax), I get the expected results.
When I run with the timeMin and timeMax params, as strings, that are exactly the same as what succeeds in the api explorier, I get 404 error:
error: {‘error’: {‘errors’: [{‘domain’: ‘global’, ‘reason’: ‘badRequest’, ‘message’: ‘Bad Request’}], ‘code’: 400, ‘message’: ‘Bad Request’}}
Code Sample:
def get_events(cal_id: str, date_start: datetime, days: int):
print('calling get_events ...')
user = anvil.users.get_user()
url = f'https://www.googleapis.com/calendar/v3/calendars/primary/events'
print(f"url: {url}")
date_end = date_start + timedelta(days=1)
print(date_start.isoformat())
print(date_end.isoformat())
refresh_token = anvil.secrets.decrypt_with_key('token_key', user['refresh_token'])
access_token = anvil.google.auth.refresh_access_token(refresh_token)
try:
response = anvil.http.request(url, json=True, method='GET',
headers={'Authorization': 'Bearer ' + access_token},
data={'singleEvents': True, # running with just the top two params, gets expected results
'orderBy': 'startTime',
# "timeMin": '2024-04-30T00:00:00-04:00', ### this fails, giving 400 error, Bad Request
# "timeMax": '2024-05-01T00:00:00-04:00'
}
# data={ #this works as expected
# 'q': 'Everett'
# }
)
except anvil.http.HttpError as e:
print(f"error: {e.content}")
raise e
if len(response['items']) < 250:
print(response)
print(len(response['items'])) # when the request succeeds, I get 250, the max
print(response['items'][0]) # when the request succeeds, this is an appt from 2008