Vb.net 在VB中创建Google日历事件

Vb.net 在VB中创建Google日历事件,vb.net,google-calendar-api,Vb.net,Google Calendar Api,我正在尝试使用GoogleAPIv3在VisualBasic中创建一个GoogleCalendar事件 我已经设法通过身份验证并从日历中获取事件,但我不确定如何保存事件,文档也没有多大帮助 以下是我当前的代码: Imports System.Collections.Generic Imports System.IO Imports System.Threading Imports Google.Apis.Calendar.v3 Imports Google.Apis.Calendar.v3

我正在尝试使用GoogleAPIv3在VisualBasic中创建一个GoogleCalendar事件

我已经设法通过身份验证并从日历中获取事件,但我不确定如何保存事件,文档也没有多大帮助

以下是我当前的代码:

Imports System.Collections.Generic
Imports System.IO


Imports System.Threading

Imports Google.Apis.Calendar.v3
Imports Google.Apis.Calendar.v3.Data
Imports Google.Apis.Calendar.v3.EventsResource
Imports Google.Apis.Services
Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Util.Store
Imports Google.Apis.Requests


Public Class ClsGoogle


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

    '' Calendar service.
    Dim service As CalendarService

    Public CalEvents As List(Of [Event]) = New List(Of [Event])     'List of events in the calendar

    Sub New()       'Classes constructor, to authenticate with google servers everytime an object is created
        Authenticate()
    End Sub

    Private Function Authenticate()     'Function that gets authenticates with google servers

        ' Add the calendar specific scope to the scopes list.
        scopes.Add(CalendarService.Scope.Calendar)


        Dim credential As UserCredential
        Using stream As New FileStream("client_secrets.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 CalendarService(initializer)
        Return 0        
    End Function




    Sub GetCalendar(MinDate As Date, Optional MaxDate As Date = Nothing)

        Dim list As IList(Of CalendarListEntry) = service.CalendarList.List().Execute().Items()     'List of all the google calendars the user has
        Dim EventRequest As ListRequest = service.Events.List(list("0").Id)     'Specifies which google calendar to perform the query

        EventRequest.TimeMin = MinDate      'Specifies the minimum date to look for in the query

        If Not MaxDate = Nothing Then
            EventRequest.TimeMax = MaxDate      'Specifies the maximum date to look for in the query
        End If
        For Each CalendarEvent As Data.Event In EventRequest.Execute.Items  'For each event in the google calendar add to CalEvents
            CalEvents.Add(CalendarEvent)
        Next
    End Sub


    Sub UpdateCalendar()
        Dim CalendarEvent As New Data.Event
        Dim StartDateTime As New Data.EventDateTime
        Dim A As Date
        A = "19/11/2014 12:00"
        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))
        Request.CreateRequest()
        Request.Execute()

    End Sub

End Class

在这里,您可以找到一个在c#中添加重复事件的示例,这与创建普通事件的方式没有太大区别,将其更改为VB代码也不难。 .

1)新事件

service.Events.Insert(CalendarEvent, service.Events.List(list("0").Id).Execute()
2) 删除事件(id为事件id)

'搜索id事件

Dim id As String = Getevent_id(oggetto, data, ora)
service.Events.Delete(service.Events.List(list("0").Id, id).Execute()
Dim id As String = Getevent_id(oggetto, data, ora)
service.Events.Update(CalendarEvent, service.Events.List(list("0").Id, id).Execute()
3) 更新事件(id为事件id)

'搜索id事件

Dim id As String = Getevent_id(oggetto, data, ora)
service.Events.Delete(service.Events.List(list("0").Id, id).Execute()
Dim id As String = Getevent_id(oggetto, data, ora)
service.Events.Update(CalendarEvent, service.Events.List(list("0").Id, id).Execute()
`------------------------------------------------------------------------------------------

Public Function Getevent_id(testo As String, data As String, ora As String)

        Dim EventRequest As ListRequest = service.Events.List(service.Events.List(list("0").Id))
        '
        EventRequest.Q = testo
        '
        For Each CalendarEvent As Data.Event In EventRequest.Execute.Items  
            Dim stringa As String = data.ToString & " " & ora.ToString
            If CalendarEvent.Start.DateTime.ToString <> Nothing Then
                If CalendarEvent.Start.DateTime.ToString.Substring(0, stringa.Length) = data.ToString & " " & ora.ToString Then
                    ' ok
                    Return CalendarEvent.Id
                End If
            End If
        Next
        Return 0
End Function
公共函数Getevent\u id(testo作为字符串,数据作为字符串,ora作为字符串)
Dim EventRequest As ListRequest=service.Events.List(service.Events.List(List(“0”).Id))
'
EventRequest.Q=testo
'
将每个CalendarEvent作为EventRequest.Execute.Items中的Data.Event
Dim stringa As String=data.ToString&&&ora.ToString
如果CalendarEvent.Start.DateTime.ToString无任何内容,则
如果CalendarEvent.Start.DateTime.ToString.Substring(0,stringa.Length)=data.ToString&“”&ora.ToString,则
”“好的
返回CalendarEvent.Id
如果结束
如果结束
下一个
返回0
端函数