Retrieve exect previous or next occurrence of a recurring event from Google Calendar

I have a recurring event in Google Calendar, and I need to fetch either the previous and next occurrence of this event, based on a given event ID. Specifically, I want to retrieve the event details for the exact occurrence before or after the specified recurring event ID.

How can I use the Google Calendar API to get the exact details for the previous or next recurrence of a given event, considering its recurrence rule (e.g., daily, weekly, etc.)?

I attempted to use the Google Calendar API to fetch the details of the previous or next occurrence of a recurring event, using the event ID and its recurrence rule. I expected to retrieve the exact details for the previous or next occurrence based on the recurrence pattern (e.g., daily, weekly, etc.). However, I wasn't able to correctly retrieve the previous or next event occurrence. Instead, the API only returned the original event or no matching results at all. this is my code

    def fetch_event_by_id(service, event_id,future,past):
        if future or past:
            pass # here i want to pass ,exect future or past one event detail, without giving timeMin and timeMax,here future and past is the number of future and past event,
        else:
            event = (
                service.events().get(calendarId="primary", eventId=event_id).execute()
            )
            event_detail = {"event": event, "earlier_events": []}
            return event_detail

Getting Recurring Events

Based on the information on the comment I can see that you are using Calendar API - List. To get the exact events that you need is the Calendar API Get Method. As has been shared through my comments on the post. What you need is the EventID of the Event you are working with. If you are going to use the endpoint shared, what it will require you is the calendarID you are working with along with the event ID. The recurring event also has a different event ID each recurrence can be fetched using the format eventID_DateTimeStamp. With this information at hand, based on the reference point of the past and future. You can Alter/Modify the DataTimeStamp after the eventID to satisfy what you are trying to fetch. Since eventID will be the same on the Original Start data and other recurrence

Sample Modification

If the Recurrence is Daily then the eventID changes should look like this

eventID_20241231T133000Z

To this one

eventID_20250101T133000Z

Sample Curl

'https://www.googleapis.com/calendar/v3/calendars/calendarID/events/eventID_20241231T133000Z?key=[YOUR_API_KEY]'

References:

Calendar API Get

Recurring Events

Back to Top