I’m trying to work with recurring appointment slots that I created in my calendar. These are the booking schedules that repeat automatically, not regular events.
I’ve been struggling to fetch these appointment schedules through the API. I tried using both events().list() and events().instances() methods but neither seems to return the appointment schedules I created.
Here’s my current Python implementation:
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
import datetime
import os
def fetch_appointments():
# Authentication setup
credentials = Credentials.from_authorized_user_file('auth.json', ['https://www.googleapis.com/auth/calendar'])
calendar_service = build('calendar', 'v3', credentials=credentials)
# Time range setup
start_time = datetime.datetime.utcnow().isoformat() + 'Z'
end_time = (datetime.datetime.utcnow() + datetime.timedelta(days=14)).isoformat() + 'Z'
# Attempt to get recurring instances
response = calendar_service.events().instances(
calendarId='primary',
eventId='my_recurring_event_id',
timeMin=start_time,
timeMax=end_time,
maxResults=50
).execute()
appointment_slots = response.get('items', [])
if not appointment_slots:
print('No appointment slots found')
return
for slot in appointment_slots:
slot_time = slot['start'].get('dateTime', slot['start'].get('date'))
print(f'{slot_time}: {slot["summary"]}')
fetch_appointments()
The code runs without errors but always returns empty results. What’s the correct way to access these recurring appointment schedules through the Google Calendar API?