Two-way sync with Google Calendar / Outlook

I use FullCalendar in my application to display events created using our own application.

I have an add / change form for creating / updating events. These events are stored in the db used by the application.

I need to move on from this and need to sync Google and Outlook calendars to my calendar. It should be 2 sync ie

If I create / edit / update an event in my calendar, it must be created / edited / deleted in Google / Outlook calendars.

It should also be the other way around.

If I made changes to the Google / Outlook calendars, it should be visible on my calendar.

I would like you to think about this:

  • Should I get all Google / Outlook events and import them into my db and then display them in my calendar view. Is it even technically possible? ie import the whole set of channel events into my db.

  • Should I just do a GET via the Google / Outlook API to receive events for a specific view, where I am now on my calendar (I will have the initial data and the end date of my calendar view) and just show them on my calendar (i.e. I do not store these external events in my db). If the user wants to make any changes to the events that need to be updated directly in the Google / Outlook calendars, through their API calls to create / update and delete.

What should be the best approach?

Edit:

I went to https://calendar.sunrise.am/ (one of the web-based calendar sync apps) and noticed

enter image description here

ie they allow you to customize the calendars / tasks of various applications in your calendar.

Having seen everything that I feel that saving all the events of all these applications in our own db application is not possible. If any change occurs with these events through my application, I must call the API of these applications in order to make this change in my application (Google Calendar, Outlook, etc.).

What do you think?

+7
java c # outlook calendar fullcalendar
source share
1 answer

To create a reliable synchronization solution, you need a few things. Most importantly, the other side (Google calendar and Outlook in this case) should cooperate with you and provide api to perform incremental synchronization. I have not watched Outlook, but the Google Calendar api provides you with everything you need.

First answer your question - yes, you need to get all the events (you can skip events in the past, though) and save them in your own database. Always querying all external sources (plus your own database) is slow, makes synchronization difficult and limits you pretty much, because you cannot easily filter or search for events in multiple sources. Below I assume that we only work with Google Calendar, I hope that Outlook is similar (but I did not check).

So, a checklist of what you need:

  • Your own event database, where the event table has several important metadata columns: Created \ Updated (the time the event was last created or updated is not related to the date of the event itself), Source (where this event occurred from Google Calendar , Outlook or your own application), UpdAtSource (the source where this event was last modified), EventID (unique identifier of the event - it is important to have this to prevent duplicates in certain cases).

  • Extract all events from the target provider initially and store them in your database. Here is a link to the structure of the Google Calendar event, and you see that there are all the necessary metadata fields (created, updated, id).

  • Now you need to keep track of new events coming from the provider. You can either do this by polling (periodically checking to see if there are new events) or by making you push provider events. Google Calendar supports both. Here is a link that describes how to implement push notifications, and here is a link that describes how to receive only new events, that is, events that you (your application) have not seen before. Please note that you do not need to get the whole list every time, and you do not need to provide some filter parameters (for example, "give me all events created after 2016-06-21"). All of this would be unreliable, but Google Calendar developers know how to make a good sync api, so they took care of this for you. Just grab and save the provided nextSyncToken and use it to make future requests. If you use push notifications - always , also periodically poll events, but not often (for example, once every few hours). Push notifications are not 100% reliable, and some may be skipped - you need to handle those using the nextSyncToken api.

  • Push the changes made by your own application to target providers. But do not do it immediately when this change is made. Instead, use a background process that pushes changes one by one for each user and provider pair. There will be network failures, conflicts will arise, so you will have to make changes in sequence, and not in parallel (again, sequentially for each user + provider pair, not globally). Save the timestamp of the last successfully clicked change (again, for each user + provider), and if the process was interrupted - you know where to start.
  • I will not describe it in detail here, but you will be in conflict, that is, when the user has changed the same event in several sources. However, if you use push notifications, conflicts will be very rare. However, you should plan them, at least in the user interface. If you find an unsolvable conflict, pause the synchronization process and ask the user how to resolve it.

So, you see that there is some work, but in the end you will make a small number of requests and receive a small amount of data with each request to the provider, and your users will be glad to see new events from their Google Calendar \ Outlook in your application immediately (and vice versa )

+10
source share

All Articles