Google Calendar API

At a previous blog of mine I wrote an article about having trouble with the fetching of items from Google Calendar with Google’s API for .Net. In post I’ll write this post in a different way.

I’m doing this site where we want to use the Google Calendar for the calendar function of the site. Now that seemed to be easy since Google as an API for .Net, but it wasn’t that easy. Now, why was that? I’ll explain why.

Firstly some of the parameters aren’t clearly explained how they are set in the objects. My main problem was that you can’t set a category to an event, even though you can grab a category property in the API. My solution to the problem was to fake a category in the header of the event and then search for those among the events I’d get.

Secondly I had a problem with that the web hotel where the site is published is in Denmark and they have apparently installed their servers with danish language settings and that caused the problem that the result from Google Calendar was presented in Danish instead of Swedish which I had wished for. The solution to this came when I started to read which parameters got set when I played around with generator of code to insert in a web page if you want the calendar presented in your own page. I then figured out which parameter I had to put in the query.ExtraParameters property, which was the “hl=sv”. Below you can see final and working code and the result of this can be view at web site of Fisks├Ątra scout troop.

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
public AtomEntryCollection GetEvents(int count, string text)
        {
            EventQuery query = new EventQuery(feedUrl);
            query.TimeZone = "Europe/Stockholm";
 
            if (!string.IsNullOrEmpty(text))
            {
                query.Query = text;
                query.SingleEvents = true;
            }
 
 
            if (count >= 0)
                query.NumberToRetrieve = count;
            else
                query.NumberToRetrieve = int.MaxValue;
 
            query.SortOrder = CalendarSortOrder.ascending;
            query.ExtraParameters = "orderby=starttime&hl=sv";
            query.StartTime = DateTime.Now;
 
            EventFeed eventFeed;
            try
            {
                eventFeed = service.Query(query);
 
 
                return eventFeed.Entries;
            }
            catch (Exception e)
            {
                return null;
            }
 
        }

About mathias

.Net system developer working mainly with CMS and then foremost with EPiServer. Other areas of interest are jQuery and writting plugins. Otherwise also interested in photography and then playing with my Nikon D70.
This entry was posted in .Net, Google, Software development and tagged , , . Bookmark the permalink.

One Response to Google Calendar API

  1. Thank you for your help. Do you happen to know how to query by the event id? I have tried several things and many hours of searching…Thanks!

Comments are closed.