public List <Event> getCalendarEntriesInRange(DateTime syncDateTime) { List <Event> result = new List <Event>(); Events request = null; EventsResource.ListRequest lr = service.Events.List(Settings.Instance.SelectedGoogleCalendar.Id); lr.TimeMin = GoogleTimeFrom(syncDateTime.AddDays(-Settings.Instance.DaysInThePast)); lr.TimeMax = GoogleTimeFrom(syncDateTime.AddDays(+Settings.Instance.DaysInTheFuture + 1)); lr.SingleEvents = true; lr.OrderBy = EventsResource.OrderBy.StartTime; request = lr.Fetch(); // Fetch all pages of events if (request != null && request.Items != null) { result.AddRange(request.Items); while (request.NextPageToken != null) { lr.PageToken = request.NextPageToken; request = lr.Fetch(); result.AddRange(request.Items); } } return(result); }
public List <Event> GetCalendarEvents(bool onlyZapEvents = true, DateTime?utcStartTime = null, DateTime?utcEndTime = null) { // by default, filters events to past month and next 3 months if (utcStartTime == null) { utcStartTime = DateTime.UtcNow.AddDays(-30); } if (utcEndTime == null) { utcEndTime = DateTime.UtcNow.AddDays(90); } EventsResource.ListRequest eventListReq = this.CalendarService.Events.List(UserCalendar); eventListReq.TimeMin = XmlConvert.ToString(utcStartTime.Value, XmlDateTimeSerializationMode.Utc); eventListReq.TimeMax = XmlConvert.ToString(utcEndTime.Value, XmlDateTimeSerializationMode.Utc); Events events = eventListReq.Fetch(); if (onlyZapEvents) { List <Event> zapEvents = events.Items.Where(e => e.ExtendedProperties != null && e.ExtendedProperties.Private != null && e.ExtendedProperties.Private.ContainsKey(ExtensionItemID)).ToList(); return(zapEvents); } return(new List <Event>(events.Items)); }
private void button2_Click_1(object sender, EventArgs e) { try { NativeApplicationClient client = new NativeApplicationClient(GoogleAuthenticationServer.Description, this.clientID, this.clientSecret); OAuth2Authenticator <NativeApplicationClient> auth = new OAuth2Authenticator <NativeApplicationClient>(client, Authenticate); // Authenticated and ready for API calls... // EITHER Calendar API calls (tested): CalendarService cal = new CalendarService(auth); EventsResource.ListRequest listrequest = cal.Events.List(this.primaryCal); Google.Apis.Calendar.v3.Data.Events events = listrequest.Fetch(); // iterate the events and show them here. // OR Plus API calls (not tested) - copied from OP's code: var plus = new PlusService(auth); plus.Key = "BLAH"; // don't know what this line does. var me = plus.People.Get("me").Fetch(); Console.WriteLine(me.DisplayName); // OR some other API calls... } catch (Exception ex) { Console.WriteLine("Error while communicating with Google servers. Try again(?). The error was:\r\n" + ex.Message + "\r\n\r\nInner exception:\r\n" + ex.InnerException.Message); } }
List <Event> GetModifiedCalendarEvents(DateTime utcModifiedAfter) { EventsResource.ListRequest eventListReq = this.CalendarService.Events.List(UserCalendar); eventListReq.UpdatedMin = XmlConvert.ToString(utcModifiedAfter, XmlDateTimeSerializationMode.Utc); Events events = eventListReq.Fetch(); if (events.Items != null) { return(events.Items.Where(e => e.ExtendedProperties != null && e.ExtendedProperties.Private != null && e.ExtendedProperties.Private.ContainsKey(ExtensionItemID)).ToList()); } return(new List <Event>()); }
private void run_Button_Click(object sender, EventArgs e) { //Calendar calendar = null; try { m_provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); m_provider.ClientIdentifier = "475623449109-og3q1tijq7kuu82i8dnfjcjklhb32g47.apps.googleusercontent.com"; m_provider.ClientSecret = "OdlJ_oaKeWQXdXEpkMsjF3HF"; m_auth = new OAuth2Authenticator <NativeApplicationClient>(m_provider, GetAuthorization); m_service = new CalendarService(m_auth); EventsResource.ListRequest listRequest = m_service.Events.List("*****@*****.**"); listRequest.MaxResults = 1; listRequest.Q = "authentication"; listRequest.TimeMax = "1981-01-01T23:59:59+05:30"; Events events = listRequest.Fetch(); //calendar = m_service.Calendars.Get("*****@*****.**").Fetch(); this.authorizationCode_Textbox.Text = "Number of Items = " + events.Items.Count; Event ev = events.Items[0]; this.authorizationCode_Textbox.Text += " \nSummary : " + ev.Summary; this.authorizationCode_Textbox.Text += " \nDescription : " + ev.Description; try { if (ev.Description.EndsWith("x")) { ev.Description = ev.Description.Substring(0, ev.Description.Length - 1); } else { ev.Description += "x"; } m_service.Events.Update(ev, "*****@*****.**", ev.Id).Fetch(); //m_service.Calendars.Update(calendar, calendar.Id).Fetch(); this.authorizationCode_Textbox.Text += "\nSucess!!!"; } catch (Exception ex) { this.authorizationCode_Textbox.Text += "After Update" + ex.Message; } } catch (Exception ex) { this.authorizationCode_Textbox.Text += "Before Update" + ex.Message; } }
public List <Event> getCalendarEntriesInRange() { List <Event> result = new List <Event>(); Events request = null; string pageToken = null; do { try { EventsResource.ListRequest lr = service.Events.List(Settings.Instance.UseGoogleCalendar.Id); //lr.TimeMin = DateTime.Now.AddDays(-Settings.Instance.DaysInThePast); //lr.TimeMax = DateTime.Now.AddDays(+Settings.Instance.DaysInTheFuture + 1); //lr.TimeZone = TimeZone.CurrentTimeZone. lr.TimeMin = GoogleTimeFrom(DateTime.Now.AddDays(-Settings.Instance.DaysInThePast)); lr.TimeMax = GoogleTimeFrom(DateTime.Now.AddDays(+Settings.Instance.DaysInTheFuture + 1)); request = lr.Fetch(); pageToken = request.NextPageToken; } catch (Exception ex) { MainForm.Instance.HandleException(ex); return(result); } if (request != null) { if (request.Items != null) { result.AddRange(request.Items); } } } while (pageToken != null); return(result); }
/********************************************** Functions ******************************************************************/ public bool GetEvents() { bool Result = false; m_Items.Clear(); try { // Fetch all TasksLists of the user asynchronously. CalendarList myCalendarList = m_Service.CalendarList.List().Fetch(); if (myCalendarList != null && myCalendarList.Items != null && myCalendarList.Items.Count > 0) { m_Entry = myCalendarList.Items[0]; EventsResource.ListRequest myRequest = m_Service.Events.List(m_Entry.Id); myRequest.MaxResults = 10000; m_Events = myRequest.Fetch(); foreach (Event myEvent in m_Events.Items) { m_Items.Add(new KalenderItem(myEvent)); } Result = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } return(Result); }