Creating a linked events in Google without using Recurrence Pattern - google-calendar-api

We are trying to implement a middle-ware application to synchronize the Google(App G) events and Our application(App A) events. The problem we are facing is in creation of recurrent events from middle-ware application to Google. The App A does not use ICS format for recurring events. Instead, it uses a concept of parent-child relationship between events to denote linked events. But while trying to insert this data in Google, we end up creating an individual event for each child event as we don't have any recurrence pattern to set in event before inserting.
We have tried to look at any solution to link the events as recurrent AFTER inserting the events to Google. But could not find any solution. Is there anything we can do to show the inserted events as linked? It would work even if the events are marked as
RecurrenceException(com.google.gdata.model.gd.RecurrenceException).
Solutions and suggestions are welcome.

Related

Google calendar api v3: update all future events in recurring series limited by count

My question: how do I update "this and all future" instances in a recurring event which is limited by count so that the total number of events stays consistent?
What is the problem:
Trying to modify recurring event and I follow the below guide:
https://developers.google.com/calendar/recurringevents
Basically to update all future recurring events using a target event, the doc says one need to do two calls:
update existing event to make so it ends before the target event date
create a new recurring event with the same fields except of those need changes.
That works fine until there is an event that is limited by the number of occurrences.
Let's say there is a recurring event limited by 10 occurrences and target event is 5th event.
Now I need to split the original so that the first 4 events goes to the original one (so I update COUNT from 10 to 4) and then I create a new recurring event that holds the rest 6 events (so COUNT is 6 in this case)
My first observation is that this is not how the split events are displayed in google calendar - if I test that manually, the both events still show 10 occurrences but the second one doesn't produce any extra events (I'd expect 14 events from developer perspective, yet there are 10 as any user would expect). That implies there is a different approach here? Is it?
Also if I end up counting manually the number of events, there are still issues with cases like deleting one of the events first (let's say, the 4th event) - now how do I know that I need to show 6 instances in the new one and not 7?
Those thoughts make me think there is a better approach, but I can't find any other alternatives. Any advice on that?
UPDATE
It seems like google does it differently: for example after changing a title for "this and future" events in calendar view, it doesn't seem to produce two different recurring events since if you try to delete "all" events, that will remove all of them completely (rather than deleting only one chunk, either before or after the target event)
It seems like they are creating a bunch of exceptions or maybe "recurring exception" or something to do that. Can't find any examples on how to do that as of now thought.
Can't find any good solution for this after a few days of research and while I need to move forward I ended up with a sort of "compromise" between "good enough UX for my case" and "breaking best practice".
So I ended up updating each event individually which goes against google's warning as shown below but I limited the max count by 50. This is not necessary what others want to do, but this is good enough for the real world use case in my app.
Warning: Do not modify instances individually when you want to modify
the entire recurring event, or "this and following" instances. This
creates lots of exceptions that clutter the calendar, slowing down
access and sending a high number of change notifications to users.
And if user needs to schedule more than that, the user is asked to use "end date" instead.
Again, not ideal by any means so if anyone knows how to handle that correctly or knows how google handles that, you are very welcome to share it! (meh... and I need that for outlook too now...)
UPDATE: just got an idea: as an improvement, one can edit either "all future events" or alternatively the master event + "all previous events" depending on the index of the target event. In this case one can limit the number of requests by 2 (so in case of 50 events I'll need to do 25 requests maximum)
So if user wants to change the title from "Hello" to "Goodby" and if the user picked event number 5 in the series of 50 events to change all future events, we can change the master event to "Goodby" which will change the title of all events, and then update the first 4 events to the original "Hello".
Obligatory summary of comments and chat:
Updating events:
To update specific events in a recurring event you need to update the individual instance by specifying the event instance ID.
This is just the event ID concatenated with a datetime stamp (you can see this when making an Events: instances request for your eventID; if your event ID is xxxxxxxxxxxx then an instance ID would be something like xxxxxxxxxxxx__20200603T170000Z).
Unfortunately there's no direct update-instances endpoint so to update multiple instances in one request you'd need to use batching
The API doesn't have a dedicated method for updating recurring events regardless of the recurrence type, and I presume this is the reason the documentation says to edit the previous recurring event by cutting it down and inserting a new one, as per Google's warning:
Do not modify instances individually when you want to modify the entire recurring event, or "this and following" instances. This creates lots of exceptions that clutter the calendar, slowing down access and sending a high number of change notifications to users.
Batching:
Making a batch update on event instances does keep count consistency. If you edit instances in a batch and then use the 'this and all future events' option when deleting one of the instances of the recurring event they do all get deleted as they're still a part of the recurrance. There is no new event being created in either scenario, the event instances are being changed.
If you play around with Events: instances and use Events: update to change only some instances of an event, then you can see that they all stay part of the same recurrence chain and there is no count change.
For arbitrary large counts, even if you have a recurring event with 9999999 instances, each event still has an ID which you can retrieve from Events: instances. It's stored as a single event for event use, but the IDs of the instances are the identifiers which are different.
Honestly, it's not great that you have to edit each one manually; for large counts like 9999999 it's basically infeasible because you'll have to make a batch request for each set of 100 instances you want to change, but it's the only option available via the API at the moment.
Feature Request:
You can however let Google know that this is a feature that is important for the Calendar API and that you would like to request they implement it. Google's Issue Tracker is a place for developers to report issues and make feature requests for their development services, I'd urge you to make a feature request there, the Calendar API feature request form can be found here.

How to find out deletion time of an event with CalDAV?

Problem description
I am using CalDAV to sync events between Google Calendar and my own calendar application. Right now i am trying to implement Deletion and Restore functionality:
Every time something is synced between my two systems, i write (meta)info about the synced event in a json file. So using that file i am able to tell in a particular moment which event were synced already and are not anymore present in the CalDAV side (Google Calendar in my current case, but could be any Calendar service that support CalDAV). So, telling if an already-synced event was deleted on the CalDAV side is no problem. Now i would like to know WHEN did the deletion take place.
What i have tried
So far i tried simply retrieving all events with
<?xml version=\"1.0\" encoding=\"utf-8\"?><d:propfind xmlns:d=\"DAV:\" xmlns:cs=\"http://calendarserver.org/ns/\"><d:prop><d:getetag /></d:prop></d:propfind>
But this only returns information about the existing (not deleted) items.
Also i tried retrieving the deleted event using its id with:
<?xml version=\"1.0\" encoding=\"utf-8\"?><c:calendar-multiget xmlns:d=\"DAV:\" xmlns:c=\"urn:ietf:params:xml:ns:caldav\"><d:prop><d:getetag /><c:calendar-data/></d:prop><d:href>{eventName}</d:href></c:calendar-multiget>
But this returns HTTP 404.
Does anyone know (or has any suggestion on) how to find out the deletion time of an event using CalDAV?
UPDATE
I found out that using Google Calendar API it is possible to retrieve a list of all the documents, and this list could include deleted ones by setting the property showDeleted to true.
But the question remains:
Does anyone know how could i implement something like this with CalDAV?
Deletion is a peculiarity of Google Calendar, and not necessarily supported by all other calendars, that is why it is not possible to obtain deletion information using just CalDAV.
You could use GoogleCalendar API to take advantage of the deletion information for that particular case while implementing CalDAV in your application: It would be something like Server-Specific functionality.

How to delete orphaned Google Calendars + Events?

My app performs a one-way sync to Google Calendar. As in, if you create an event in my app it will be added to Google Calendar, but you can't update that event from Google Calendar.
I store all the Google Calendar IDs and Event IDs that their API gives me back so that I can update the calendars + events later.
However, I'm concerned about orphaned records. If, for example, someone deletes an event in my app but either the API request fails to delete the corresponding event from Google Calendar or my app has a bug in it, then that record will become orphaned -- it will exist on Google Calendar but I will have no reference to it.
So what's the best way to delete orphaned records?
Here are my ideas:
Download a list of every single event ID in Google Calendar, fetch all the event IDs out of my database, do a set subtraction to determine which ones are orphaned, and then delete those one-by-one.
Delete the entire calendar if I notice a mishap, and then re-sync all the events.
The problem with (1) is that it might get quite memory intensive once I've accumulated a lot of events. The problem with (2) is that a full re-sync can take awhile and those events will be missing from Google Calendar while the sync is happening. Plus, I might have a race-condition if users are creating new events during the sync.
What's the best approach? Are there any other solutions?

Querying Event Flow with Google Analytics API?

Using: Universal Analytics (analytics.js)
I am currently testing user experience across a site by triggering different events upon pageView. On a given pageView, multiple events may be triggered.
I am interested in determining what events (or sequence of events) may lead to a conversion being triggered. In the frontend, this can be achieved via Event Flow or Goal Flow visualizations. Unfortunately I could find nothing online regarding querying Event Flow specifically.
Is it possible to query Event Flow from the Google Analytics API? If not, are there any workarounds that would allow us to quantify impact from different flows?
There isnt a way of doing it with the API. I want to start by saying i havent tried doing this I am just going on what i would do if i did want to attempt to do this.
The flow apears to start with any of the normal dimensions country for example. My first idea was the ga:goalpreviousstep1 dimensiosn then i remembered they cant be queried with other dimensions.
I would look into ga:previousPagePath and ga:nextPagePath see what they come back with. queried along with your goal or event they might give you an idea of what the user was doing.

Copy Event from One Calendar to another

I am creating an app in asp.net for Google calendar integration. When we insert a particular event to the calendar then at the same point i want to copy the same calendar event in to another calendar and i want to do the same process in a single request. So may any one please guide me for this problem. I am using google calendar version 3 for this. Thanks in advance
Is it necessary that they be two separate Calendar events? If not, you should be adding the second calendar as an attendee of the event rather than creating a copy of the event. See the events reference and look for the attendees list attribute. This can be achieved in a single API call.
If it is indeed necessary that the events are entirely separate and independent of each other, it will require two events.insert() operations, one on each calendar. However, as long as the user you are authenticating as has access to both calendars, it should be possible to batch the two operations into a single HTTP call.

Resources