lunedì 29 ottobre 2012

C# Google API - Retrieve Own Calendars List

I think google calendar is a very useful service. 
The following code shows how to get the list of our calendars, if we want to do our own program to getting them.

public void LoadCalendars()
    //first i clear the ComboBox 
    CalendarService service = new CalendarService("appName");
    service.setUserCredentials("", "yourPassword");

    CalendarQuery query = new CalendarQuery();

    query.Uri = new Uri("");
    CalendarFeed calendarFeed = (CalendarFeed)service.Query(query);

    foreach (CalendarEntry entry in calendarFeed.Entries)
        // see the code down for the definition of the "ComboboxItem" object  
        ComboboxItem item = new ComboboxItem();
        item.Text = entry.Title.Text;

        //take only the part that refers to the calendar for future use
        item.Value = entry.Id.AbsoluteUri.Substring(55);


Here the definition of the "ComboboxItem" class used above to filling the combobox
class ComboboxItem
        public string Text { get; set; }
        public object Value { get; set; }

        public override string ToString()
            return Text;

** I want to remeber to go here to get  Application-specific password

My Two Cents...

3 commenti:

  1. It's great.

    Now using Nuget:

    Install-Package Google.GData.Calendar

    New API:
    Install-Package Google.Apis.Calendar.v3

    I dont' know the differences neither good patterns and practices about it.

  2. Now, I get 403 error about it.

    Back in November 2011, we announced the deprecation of the Calendar GData API (v1, v2) when the APIv3 was made available. We’ll now be shutting down these older versions on November 17, 2014.

    Any service dependent on the Calendar GData API (v1, v2), such as the Google Calendar Connectors (GCC), will no longer work as intended. GCC users should update to use Calendar Interop or their own custom built connectors that sync with v3 of the API.

  3. Migration guide: