Mike Baxter
Mike Baxter

Reputation: 7268

Google Calendar sync with database

I am using google calendar api v2, and currently looking for a way to synchronize a google calendar with a local application/database (using C#, data being stored in a SQL Compact database). I am doing this because I am aiming to create an application that still functions once an internet connection has been lost (therefore data needs to be stored locally). Querying and updating events on the application level work fine, however I am running into several issues:

1) Querying if an event (stored in DB) still exists in google calendars:

My current system is more-or-less working. For each calendar event stored in the database, I run a query against google calendar for that particular 'key' (approx 26 character string) - if nothing is returned, then the event must no longer exist. But this causes two problems; the first being that it is expensive to do separate queries for each calendar event, and isn't really very usable for larger calendars. The second problem is that after a while the calendar starts to always return nothing, making the application think that all the events have been deleted - obviously not ideal as the last thing I want to do is delete all the local events. My best guess is that google starts to return null perhaps because I am sending too many requests - although I can't be sure on that.

Edit: I have solved this problem using entry.Status. If an event is cancelled, it returns the url: http://schemas.google.com/g/2005#event.canceled

Using this you can detect which events have been deleted on the google's side.

2) Querying events modified-date on google calendars:

Currently if I want to query events that have been modified after a certain date, I add the following line to my query:

query.ExtraParameters="orderby=startime&sortorder=ascending&updated-min=" + date;

This returns all calendar events modified since the supplied date, however, to my knowledge, there doesn't seem to be any way of retrieving the actual date an event was modified. At least, not in v2. Is this correct? If so, how else could I achieve this?

The problems I'm having are either because the functionality of the google calendar api is limited, or there isnt enough information in the documentation.

If anyone could offer any insight on these issues then it would be much appreciated.

Upvotes: 0

Views: 3912

Answers (1)

visionDev
visionDev

Reputation: 86

Thanks for the above - it helped me with getting back the edited appointments based on a modified date. When returned, we get the modified date as follows - hopefully this is what you mean/were after:

EventFeed calFeed = service.Query(query) as EventFeed;

while (calFeed != null && calFeed.Entries.Count > 0) {
    foreach(EventEntry entry in calFeed.Entries) {
        DateTime modified = entry.Edited.DateValue;
    }
}

Upvotes: 2

Related Questions