Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Calendar API: How to get a CalendarEntry for the default Calendar?

Tags:

I'm trying to get the 'normal' url for a users default calendar feed (e.g. http://www.google.com/calendar/feeds/[email protected]/private/full). I would like to use the [email protected] part of the URL as a unique ID for that calendar.

I know I can do things with the default calendar using the URL http://www.google.com/calendar/feeds/default/private/full. However, I can't find a way to construct a CalendarEntry from that URL (I could then try SelfUri and some other properties to see if the 'normal' url is in there somewhere), or to convert it to the 'normal' url in any way.

And I know I can get the list of Calendars like this:

CalendarQuery query_cal = new CalendarQuery();
query_cal.Uri = new Uri( "http://www.google.com/calendar/feeds/default/allcalendars/full" );
CalendarFeed resultFeed = (CalendarFeed) service.Query( query_cal );
foreach ( CalendarEntry entry in resultFeed.Entries )
{ ... }

However, I can't find any way to know which of those entries matches the default calendar.

Or any other way to get that normal url for the default calendar.

like image 684
Legolas Avatar asked Feb 19 '10 19:02

Legolas


2 Answers

It's probably not the best method, but I use this and it works:

    feedstring = resultfeed.Entries.Item(calendarIndex).Id.AbsoluteUri.Substring(63)
                postUristring = "https://www.google.com/calendar/feeds/" & feedstring & "/private/full"

Dim postUri As New Uri(postUristring)

Just use calendarIndex = 0 for the default calendar. Shouldn't be too hard to convert to C#!

like image 76
jazzwhistle Avatar answered Oct 20 '22 00:10

jazzwhistle


Thank you SO much! That works perfectly! Here is my final code:


        CalendarQuery query = new CalendarQuery();
        query.Uri = new Uri("https://www.google.com/calendar/feeds/default/allcalendars/full");
        CalendarFeed resultFeed = (CalendarFeed)service.Query(query);
        int calendarIndex = 0;
        string postUristring = string.Empty;
        foreach (CalendarEntry entry2 in resultFeed.Entries)
        {
            if (entry2.Title.Text == "My Pregnancy Calendar")
            {
                string feedstring = resultFeed.Entries[calendarIndex].Id.AbsoluteUri.Substring(63);
                postUristring = "https://www.google.com/calendar/feeds/" + feedstring + "/private/full";
            }
            calendarIndex++;
        }
like image 44
Brenda Avatar answered Oct 20 '22 01:10

Brenda