Google Calendar API创建全天活动VB.net

时间:2018-03-15 15:55:43

标签: vb.net google-calendar-api

我正在尝试使用vb.net中的winforms应用在Google日历中创建一整天的活动。我可以使用开始和结束时间创建一个正常的事件,但我无法弄清楚如何整天制作一个事件。以下注释掉的代码适用于“一天中的时间”事件。

        'Dim CalendarEvent As New Data.Event
        'Dim StartDateTime As New Data.EventDateTime
        'Dim datestr As String
        'datestr = UIFORM.REQDATE.Value.ToString("dd/MM/yyyy") & " 07:00 am"
        'StartDateTime.DateTime = Date.ParseExact(datestr, "dd/MM/yyyy hh:mm tt", System.Globalization.DateTimeFormatInfo.InvariantInfo)
        'datestr = UIFORM.REQDATE.Value.ToString("dd/MM/yyyy") & " 03:00 pm"
        'Dim EndDateTime As New Data.EventDateTime
        'EndDateTime.DateTime = Date.ParseExact(datestr, "dd/MM/yyyy hh:mm tt", System.Globalization.DateTimeFormatInfo.InvariantInfo)
        'CalendarEvent.Start = StartDateTime
        'CalendarEvent.End = EndDateTime
        'CalendarEvent.Description = "Inserted from Order Entry"
        'CalendarEvent.Summary = NUMBER & " - " & NAME
        'Authenticate()
        'service.Events.Insert(CalendarEvent, "primary").Execute()

根据一些消息来源,我只需要指定日期,没有时间整天开展活动。这是我尝试过的:

Dim CalendarEvent As New Data.Event
    Dim datestr As String
    datestr = UIFORM.REQDATE.Value.ToString("yyyy-MM-dd")
    CalendarEvent.Start.Date = datestr
    CalendarEvent.End.Date = datestr
    CalendarEvent.Description = "Inserted from Order Entry"
    CalendarEvent.Summary = "all day test"
    Authenticate()
    service.Events.Insert(CalendarEvent, "primary").Execute()

一旦遇到CalendarEvent.Start.Date = datestr,我就会收到一个对象引用错误。

1 个答案:

答案 0 :(得分:1)

我认为你需要这样做:

Dim datestr As String = UIFORM.REQDATE.Value.ToString("yyyy-MM-dd")
Dim StartDateTime As New Data.EventDateTime With {.Date = datestr}
Dim EndDateTime As New Data.EventDateTime With {.Date = datestr}

Dim CalendarEvent As New Data.Event With {
    .Start = StartDateTime,
    .End = EndDateTime,
    .Description = "Inserted from Order Entry",
    .Summary = "all day test"
}
Authenticate()
service.Events.Insert(CalendarEvent, "primary").Execute()

基于此处的API参考:

  

https://developers.google.com/resources/api-libraries/documentation/calendar/v3/csharp/latest/classGoogle_1_1Apis_1_1Calendar_1_1v3_1_1Data_1_1EventDateTime.html

此Stack Overflow问题的进一步帮助:

  

Creating a Google Calendar event in VB