【问题标题】:Google Calendar API create all day event VB.netGoogle Calendar API 创建全天事件 VB.net
【发布时间】:2018-03-16 00:18:44
【问题描述】:

我正在尝试从 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,我就会收到对象引用错误。

【问题讨论】:

  • 看起来CalendarEvent.Start 指的是DateTime 属性。 DateTime 值的 Date 属性是 ReadOnly。此外,DateTime总是具有时间分量。即使您为其分配了仅日期值,该属性仍将具有午夜的时间分量。要发送一个完全没有时间组件的值,您可能需要进入较低级别并构建自定义 JSON 请求。
  • 我理解了大约一半。你说的低级是什么意思?应该只有一个布尔值 .allday=true... 但不,Google 必须复杂
  • 没关系...我终于找到了日历 API 的正确文档,它根本不是 DateTime 属性。 API 有自己的 EventDateTime 类型:developers.google.com/resources/api-libraries/documentation/…

标签: vb.net google-calendar-api


【解决方案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

在堆栈溢出问题的进一步帮助下:

Creating a Google Calendar event in VB

【讨论】:

  • 是的!非常感谢!
  • 我什至不知道我可以在 vb 中使用 with
猜你喜欢
  • 2014-09-18
  • 2022-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多