I have been reading the docs and playing with different EventQuery parameters for days now. I am using C# .NET with google’s .net api to get the events from a public calendar I set up. I can get the events from the api just fine but I can’t get it to give me the next upcoming events by date. My calendar has mixed recurrence events with one-shot events. I have read stuff on the internet to use direct query parameter strings in the request uri but doesn’t seem to work right when using it in the .net api structure. Here is what I have currently as my base:
CalendarService myService = new CalendarService("testGoogleCalendar-1");
EventQuery myQuery = new EventQuery();
myQuery.Uri = new Uri(CalendarURI);
myQuery.NumberToRetrieve = NumberOfEvents;
EventFeed calFeed = myService.Query(myQuery);
foreach (AtomEntry entry in calFeed.Entries)
{
LiteralControl test = new LiteralControl("<p><b>" + entry.Title.Text + "</b></p>");
this.Controls.Add(test);
}
I have tried playing with the EventQuery’s members StartDate, StartTime, EndTime, SortOrder, FutureEvents and even tried adding “?orderby=starttime” to the CalendarURI local member.
The api query’s seems to return the order of published date of the event which is when I created the event in the calendar not when the event is going to take place.
I have also been trying to get just the date and time of the event from the AtomEntry object so I can sort it myself and format it with the title in my control but the only place I see it is in AtomEntry’s Content.Content which also has other stuff I don’t really want. Is there a DateTime member to AtomEntry for this so I can just get the date?
This one has really got me confused right now so any help is appreciated.
I haven’t used the GData calendar API from .NET, but I’m pretty familiar with it in Java. The start time of an event will depend on the type of an event. A recurrent event doesn’t have any start times as such, but a “single” event may actually have multiple times. These are stored as
<gd:when>elements – that’s what you need to look for.It does look like
orderby=starttimereally should work though. It may be worth using WireShark or something similar to see the exact query going out and the exact results coming back, to check it’s not something in the API causing problems – in particular, it could be that using that in the Uri property isn’t supported for some reason…EDIT: Have you tried setting
? That’s probably the safest way of getting it into the final query uri…