Introduction
If Calendar Creator is used as your master calendar, this program can be used to sync your Google Calendar to your Calendar Creator calendar. It can also be viewed as an example of how to use Google Calendar API v3.
Background
I use Calendar Creator as my master household calendar. To push the calendar to our Android phones, I would occasionally delete my entire Google Calendar and then import the Calendar Creator Export .CSV file. I could only import the file after I had done significant editing because the Calendar Creator Export .CSV file is not in the format that Google Calendar expects. This took a lot of mouse clicks and a fair amount of time. I decided to write a program to read the Calendar Creator Export .CSV file and sync my Google Calendar to its contents using the Google Calendar API v3. My program now takes 16 seconds to update the Google Calendar after only one double-click to initiate it.
Using the Code
- You must have a Google OAUTH 2.0 Credential of the type Client ID and the associated Client Secret to compile and use this program. You can obtain these by creating a project with the Google Developers Console. After that, complete the process in the APIs & auth section. First, create a new Client ID of type "Installed application." Then, configure the Consent screen by entering your gmail.com email address and your product name. Finally, enable the
Calendar
API in the APIs section.
The first time that the program is executed on a computer, a browser window will open to request permission. A OAuth 2.0 token is saved and automatically refreshed by the .NET Calendar
API v3 library.
Edit the following two lines in Main.vb to insert your Client ID and Client Secret:
Private Const GOOGLE_CLIENT_ID As String = "YOUR CLIENT ID GOES HERE"
Private Const GOOGLE_CLIENT_SECRET As String = "YOUR CLIENT SECRET GOES HERE"
- The Google Calendar API and associated NuGet packages are not included with the source code attached to this tip article. To add these to your project in Visual Studio, select Tools / NuGet Package Manager / Package Manager Console and enter the following command:
Install-Package Google.Apis.Calendar.v3
- You may want to customize this program to ensure that all of the custom event categories that you use in Calendar Creator to signify All Day Events are included in the following boolean statement. This statement is found in the
CalendarCreatorEventConstructor
method of the clsCalendarCreatorEvent
Class in Main.vb.
m_AllDay = strCategoryUpcased = "BIRTHDAYS" OrElse _
strCategoryUpcased = "ANNIVERSARY" OrElse _
strCategoryUpcased = "ALL DAY EVENT" OrElse _
strCategoryUpcased.Contains("US HOLIDAYS")
- Those categories and any event that starts at 12:00AM and ends at either 11:59PM or 12:00AM are treated as an All Day Event. In Google Calendar, All Day Events appear in a separate section at the top of each day column.
If strStartTime = "0:00" AndAlso (strStopTime = "0:00" OrElse strStopTime = "23:59") Then
m_AllDay = True
End If
If m_AllDay Then
strStartTime = "0:00"
strStopTime = "0:00"
End If
- When executing this program, the
commandline
parameter must be the full path filename to the Calendar Creator Export .CSV file.
Example:
SyncCalendarCreator.exe C:\users\YOUR_USER_NAME\Desktop\Export.csv
Points of Interest
- The following Google
Calendar
APIs are used in this program. Documentation for these and other Google Calendar
APIs is available on the Calendar API v3 Class Documentation page.
CalendarService.CalendarList.List
CalendarService.Events.List
CalendarService.EventsResource.DeleteRequest
CalendarService.EventsResource.InsertRequest
CalendarService.EventsResource.UpdateRequest
- If there are any events in the Google Calendar that are configured as recurring events, they are ignored by this program. The Calendar Creator Export .CSV file contains only individual day events. Any recurring events configured in Calendar Creator are output to the exported .CSV file as multiple events on their respective days.
- This program uses the earliest date and latest date found in the Calendar Creator Export .CSV file to determine how much of your Google Calendar is to be modified.
colCalendarCreatorEvents.Sort(AddressOf EventComparer)
dtStart = colCalendarCreatorEvents.Item(0).StartDate.Date
dtStop = DateAdd(DateInterval.Day, 1, colCalendarCreatorEvents.Item
(colCalendarCreatorEvents.Count - 1).StartDate).Date
History
- 08/11/2015: Initial version
- 08/23/2015: Use a custom credentials
FileDataStore
with the UserName
in the filename. - 08/24/2015: Small change to comment in source code.