Request individual events from Google Calendar

Right now I have a very simple query that pulls records containing a string and a specific date range.

EventQuery eQuery = new EventQuery(calendarInfo.Uri.ToString()); eQuery.Query = "Tennis"; eQuery.StartDate = startDate; eQuery.EndDate = endDate; EventFeed myResultsFeed = _service.Query(eQuery); 

Upon request, myResultsFeed will contain atomEntryCollection. Each atom has a headline. As I configured it, there may be several entries with the same name.

I would like my query to be able to select unique names. Is it possible?

API Docs Link

I assumed I could use the WHERE object

 Where x = new Where(); x.yadayada(); 

but it cannot be passed to _service.Query ()

I am also studying the .extraparameters object. is it possible to do something like this?

 eQuery.ExtraParameters = "distinct"; 

Peering at the Partial Answer feature.

http://code.google.com/apis/gdata/docs/2.0/reference.html#PartialResponse

It looks pretty promising.

+4
source share
2 answers

I don’t think what you are trying to do using the Google data API. However, based on @Fueled's answer, you can do something similar if you need an AtomEntry collection.

 // Custom comparer for the AtomEntry class class AtomEntryComparer : IEqualityComparer<AtomEntry> { // EventEntry are equal if their titles are equal. public bool Equals(AtomEntry x, AtomEntry y) { // adjust as needed return x.Title.Text.Equals(y.Title.Text); } public int GetHashCode(AtomEntry entry) { // adjust as needed return entry.Title.Text.GetHashCode(); } } EventFeed eventFeed = service.Query(query) var entries = eventFeed.Entries.Distinct(new AtomEntryComparer()); 
+3
source

This is probably not the solution you were looking for, but since you have AtomEntryCollection on hand (which implements IEnumerable<T> ), you can use LINQ to get individual headers, for example:

 EventFeed feed = service.Query(query); var uniqueEntries = (from e in feed.Entries select e.Title.Text).Distinct(); 

And then let's get to them with a simple foreach :

 foreach (var item in uniqueEntries) { Console.WriteLine(item); } 

But then you only have a string collection representing Event headers, not an AtomEntry collection. I think you could link them together in a dictionary. Not optimal, but should work.

0
source

All Articles