martedì 30 ottobre 2012

C# Google API - Insert Calendar Feed

If we want to insert a reminder/appointment (feed) in our calendar, using our application, the following code shows how to do it


private void InsertCalendarFeed()
        {
            CalendarService service = new CalendarService("cl");

            service.setUserCredentials("yourMail@gmail.com", "yourPassword");
            service.QueryClientLoginToken();

            EventEntry entry = new EventEntry();

            entry.Title.Text = txt_titolo.Text;
            entry.Content.Content = "the content of the feed";
            When w = new When();
            DateTime start = Convert.ToDateTime("start date--> dd/mm/yyyy hh:mm:ss");
            DateTime end = Convert.ToDateTime("end date--> dd/mm/yyyy hh:mm:ss");
            w.StartTime = start;
            w.EndTime = end;
          
            entry.Times.Add(w);

                      //select the calendar where the feed will be inserted
            //"cmb_calendars" is a ComboBox on the form containing the calendar.
            // view: C# Google API - Retrieve Own Calendars List
            Uri postUri = new Uri("http://www.google.com/calendar/feeds/" + ((ComboboxItem)cmb_calendars.SelectedItem).Value.ToString() + "/private/full");

            AtomEntry insertedEntry = service.Insert(postUri, entry);
             
            // insert ok
        }


** I want to remeber to go here http://support.google.com/mail/bin/answer.py?hl=it&answer=1173270 to get  Application-specific password


My Two Cents...

Nessun commento:

Posta un commento