Find an event in a calendar - google-calendar-api

I'm writing an app that reads a Google Sheet that I have read access to. This is working just fine. It contains upcoming dates for things. The sheet contains usually no more than 20 - 30 upcoming events. Events that have passed are ignored.
I need to take these upcoming events and add them to a calendar. Adding events is ok. The problem is that if the app runs again say a week later, the events that are already on the sheet are added again, so I need a way of searching for an event in a calendar based on the date of the event. If I find an event at that date and time, then I can ignore it and move to the next one. It seems that searching for an event requires a calendar ID and an event ID. Is there a way to search for an event by giving a date and time, and say a partial summary?
Failing that, any other options? The data in the Google Sheet I have read access to only. My app doesn't store anything locally. The intention is to read the sheet and add events but not add duplicate events.

To get events you either use events.get where you provide the calendarId and eventId to fetch a specific event or Events.list to get all events.

Related

How to fetch events just for the month and year displaying by the user?

i use VueJS 3 with type script and Full Calendar V6.
I need to load events when user click on Next or Previous month/year.
I need to fetch events just for the month and year displaying by the user.
I dont want to make a query that retrieves all the events in the database.
I use the "events:" property in calendarOptions.
But the only way I found is to pass an asynchronous request to this property (events:). This property will then distribute the events properly in the calendar.
How to make a dynamic and parameterized request, according to the month and year consulted by the user?

Google Calendar API V3: Identifying edited one-offs of recurring events?

I am currently listing all events from a Google Calendar using the "singleEvents" parameter set to true, which splits recurring events into individual events – which is good. However, I'm running into an issue when an instance of a recurring event is edited, and the edits are saved with the "Only this event" option in the Calendar UI.
What I need to do is be able to identify which of these recurring event instances have been edited, and which have not. It seems the API response data does not provide any indications of whether this is an instance of the unedited recurring event, or an edited one-off. The response for an unedited instance of a recurring event and an edited instance are more-or-less the same, save the description field, which was edited.
The reason I need to differentiate edited versus unedited recurring event instances is that I am dynamically creating event detail pages from the list of single events. I would like to have one page be for the recurring event itself, and another for a "one-off" of that recurring event. E.g:
allmyevents.com/events/my-recurring-event --> page showing recurring event with recurrence information
allmyevents.com/events/my-recurring-event/16-4-2020 --> page showing specific instance of recurring event, which has been edited
Currently, I'm able to do this by creating an entirely new event at the same date and with the same title as the recurring event instance I want to replace, and writing hacky comparison logic to tell if this is a replacement event, but this is counter-intuitive for event/content management.
Answer:
You can use the Calendar API Events: instances endpoint to return all instances of a recurring event. All the events which have been edited on their own will not be returned.
More Information:
The Events: instances endpoint of the Calendar API will return all instances of a recurring event for a calendarId and eventId specified. Any of these that have been edited are omitted.
It's a bit of a workaround, as these events can't be obtained directly, but by obtaining the list of events as you have already been doing and then removing the events which are returned by Events: instances, you can build a list of all the events which have been edited with the 'Only this event' option.
Psuedo-code:
You can do something like this:
eventsList = Calendar.Events.List(calendarId, singleEvents=true)
eventsInstances = Calendar.Events.Instances(calendarId, recurringEventId)
singleEvents = eventsList
for each instance in eventsInstances :
if eventsList.items contains instance :
singleEvents.remove(instance)
return singleEvents
Where the returned singleEvents variable will be a list of all the events that have been edited manually.
References:
Events: instances | Calendar API | Google Developers
Recurring Events | Calendar API | Google Developers
I've been puzzling through this same issue, and I think I've found a way forward that doesn't involve going through every single instance to check if they've been moved/edited:
Each event returned by the Calendar API has an iCalUID field. For a standalone event, this should match the event's id, with an #google.com suffix. e.g. an event with the id of abcdef has an iCalUID of abcdef#google.com.
When it comes to recurring series, every single instance of that event has the same iCalUID value - and, most importantly, you can use iCalUID as a filter when listing events, which will return the main recurring series event and all modified instances. Unmodified instances are not returned.
Tracking which instances have been deleted is slightly more fiddly. They might be returned in the list with the matching iCalUID, but with a status set to cancelled. Or, they may be specified within the recurrence property (an array of strings) on the main series event as timestamps (within the given time-zone, which should match whichever time-zone the main series event uses):
[
"RRULE:FREQ=WEEKLY,COUNT=5",
"EXDATE;TZID=Australia/Melbourne:20211227T110000,20220103T110000"
]
I haven't figured out why some recurring events use the specific-instances-as-cancelled approach, and others use the EXDATE approach (and I think they can also be combined, so don't presume the presence of one rules out the other). Given both are possible, you'll have to allow for that.

Google Calendar API - How to set Auto Join option for event participant

I have create an Event using Google Calendar API using 'hangoutsMeet' option.
However, despite being event participant, end users are getting 'Ask to join' button.
Is there any option which could allow event participant to join automatically without approval.
According to the Calendar API documentation on the day of this post it is not possible to automatically join participants to individual events as they will be required to accept or reject the event invitation.
From the documentation linked above:
Inviting someone to an event will put a copy of that event on their calendar. The invitee can then accept or reject the invitation, and to some extent also modify their copy of the event.
I hope this has helped you. Let me know if you need anything else or if you did not understood something. :)

Outlook events sent to a google calendar - event ids change unexpectedly?

I am creating a meeting series from an outlook client, on an office365 mailbox.
The invited user is on g-suite (email, calendar...).
My code connects to google calendar via the API and periodically checks of event changes \ new events \ cancelled etc.
I store the event ids in my database and use them to match to the event IDs I read from google calendar.
When a whole meeting series is changed - for instance a weekly series gets a new starting time - the event IDs returning from google calendar APIs - change!
I am not sure if the IDs are generated by office\outlook or by g-suite.
I am not sure what's the right way to match the events I stored with their old IDs, to the new events coming in.
If you read the Google API Documentation, it states that recurring events are composed of instances. The recurring event is a parent and individual instances are its children. Each child has a recurringEventId which identifies its parent. Their individual instance ids might change when they are changed.
See the following: https://developers.google.com/calendar/recurringevents#modifying_or_deleting_instances

Google Calendar API: Editing a single occurrence of a recurring event

Using the Google Calendar API, how can I edit a single occurrence of a recurring event? (the web interface allows me to do that)
Reading through some of the google forums on this I came across an answer from a google employee:
What you can also do is to retrieve
the events by adding the query
parameter 'singleevents=true' to the
feed URL. This will expand the
recurring events into multiple events.
http://code.google.com/apis/calendar/data/2.0/reference.html#Parameters
You will just have to modify the
desired events and it will create the
exception.
About the "Forbidden g:originalEvent
[2010-02-08 06:00:00] does NOT
correspond to an instance of the
recurring event": this mean that the
When object set in the OriginalEvent
doesn't match the time of the
occurrence of the recurring event.

Resources