Write to google calendar v3 RRS feed

  • Question

  • I have been struggling with this for a week. I can make a successful connection and retrieve information from google calendar without any problems.  I do not know how to add an event to the calendar.  Here is what I have so far, and any help or advice would be helpful.

    Imports Google.Apis.Auth.OAuth2
    Imports Google.Apis.Calendar.v3
    Imports Google.Apis.Calendar.v3.Data
    Imports Google.Apis.Services
    Imports Google.Apis.Util.Store
    Imports System.IO
    Imports System.Threading
    Imports Google.Apis.Calendar.v3.EventsResource

    Module addgoogleevent
        '' Calendar scopes which is initialized on the main method.
        Dim scopes As IList(Of String) = New List(Of String)()

        '' Calendar service.
        Dim service As Google.Apis.Calendar.v3.CalendarService

        Sub main()       'Classes constructor, to authenticate with google servers everytime an object is created
            'access json file and send to google 
            Dim credential As UserCredential
            Using stream As New FileStream("client_secret.json", FileMode.Open, FileAccess.Read)
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets, scopes, "user", CancellationToken.None,
                        New FileDataStore("Calendar.VB.Sample")).Result
            End Using
            ' Create the calendar service using an initializer instance
            Dim initializer As New BaseClientService.Initializer()
            initializer.HttpClientInitializer = credential
            initializer.ApplicationName = "VB.NET Calendar Sample"
            service = New Google.Apis.Calendar.v3.CalendarService(initializer)
            ' Fetch the list of calendar list

        End Sub

        Sub UpdateCalendar()
            Dim list As IList(Of CalendarListEntry) = service.CalendarList.List().Execute().Items()
            Dim EventRequest As ListRequest = service.Events.List(list("0").Id)
            Dim CalendarEvent As New Data.Event
            Dim StartDateTime As New Data.EventDateTime
            Dim A As New DateTime(2016, 9, 19, 12, 0, 0)

            StartDateTime.DateTime = A
            Dim b As Date
            b = A.AddHours(2)
            Dim EndDateTime As New Data.EventDateTime
            EndDateTime.DateTime = b
            CalendarEvent.Start = StartDateTime
            CalendarEvent.End = EndDateTime
            CalendarEvent.Id = System.Guid.NewGuid.ToString
            CalendarEvent.Description = "Test"

            Dim Request As New InsertRequest(service, CalendarEvent, service.Events.List(list("0").Id).ToString)
            Request.CalendarId.Insert(Val(StartDateTime), Val(EndDateTime))
        End Sub
    End Module
    Wednesday, September 28, 2016 3:56 AM


All replies