Search code examples
google-calendar-api

Extract upcoming events using Google Calendar API - VB.NET


I am using this VB code to retrieve the upcomming events from my calendar

Private Sub LoadCalendars()
    Dim service As CalendarService = GetCalendarService()
    Dim objCalendarListRequest As CalendarListResource.ListRequest = service.CalendarList.List
    objCalendars = objCalendarListRequest.Execute()
    If objCalendars Is Nothing Or objCalendars.Items.Count = 0 Then
        '** No calendars.  Something is wrong.  Give up and die.
        MsgBox("No calendars found?  That's weird.")
        End
    Else
        For Each objCal As Data.CalendarListEntry In objCalendars.Items
            Console.WriteLine(objCal.Summary)
        Next
    End If
End Sub

But I'm not able to :

  1. retrive only the 'primary' calendar
  2. retrieve only the upcomming events

I found out several examples in C#, but I need it in VB.

This example in C# works fine and does exactly what I need, my issue how to do the same in VB..?

// Define parameters of request.
        EventsResource.ListRequest request = service.Events.List("primary");
        request.TimeMin = DateTime.Now;
        request.ShowDeleted = false;
        request.SingleEvents = true;
        request.MaxResults = 10;
        request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

Some suggestion..? Tks.


Solution

  • Here is the solution :

    Dim request As EventsResource.ListRequest = service.Events.List(objCal.Id)
    request.TimeMin = Now.Date()
    request.ShowDeleted = False
    request.SingleEvents = True
    request.MaxResults = 10
    request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime