Search code examples
.netgoogle-calendar-apigdata-api

Google Calendar's EventQuery not retrieving correct entries


I am trying to retrieve South African public holidays using Google's .NET Calendar API.

I have the following issues:

  1. Some of the retrieved data is outside of the specified EventQuery range. (Both before and after the given date range)
  2. Some of the calendar entries are missing. One of them being Christmas 2011-12-25

I verified that this particular public calendar has the correct dates by viewing it online.

My best guess is that I am using the API incorrectly and that I am querying something like the calendar entry's created/updated date instead of the event date.

Code:

var feedUrl = "http://www.google.com/calendar/feeds/en.sa%23holiday%40group.v.calendar.google.com/public/full";
var service = new CalendarService("My application name");

var qry       = new EventQuery(feedUrl);
qry.StartDate = new DateTime(2011, 1, 1);
qry.EndDate   = new DateTime(2012, 1, 1);

EventFeed results = service.Query(qry);

foreach (EventEntry entry in results.Entries)
{
    if (entry.Times.Count == 0)  
       continue;

    // Using entry.Times[0].StartTime results in 
    // missing data and data outside of the given search criteria.
}

I am using the latest available Google .NET Data API 1.7.0.1

What am I doing wrong?


Solution

  • Found the issue:

    qry.StartDate = new DateTime(2011, 1, 1);
    qry.EndDate   = new DateTime(2012, 1, 1);
    

    should be:

    qry.StartTime = new DateTime(2011, 1, 1);
    qry.EndTime   = new DateTime(2012, 1, 1);
    

    This solves both of my issues mentioned in my question. (Not sure why the EventQuery class has both Date/Time properties, this is confusing when only the one set works).