将.Net API包装器用于Google Calendar API。

  • 首先获取主日历ID
  • 获取主日历的时区(返回良好的数据,例如“America / Los_Angeles”)
  • 创建日历事件。设置开始时间和结束时间。设置时区。
  • Dim eStart As New EventDateTime
    eStart.DateTime = _startAt
    eStart.TimeZone = GoogleTimeZone
    Dim eEnd As New EventDateTime
    eEnd.DateTime = _endAt
    entry.Start = eStart
    entry.End = eEnd
    eEnd.TimeZone = GoogleTimeZone
    CalService.Events.Insert(entry, calendarid).Execute()
    

    但是,当指定的开始时间是11am时,将在凌晨3点创建事件。

    Google API文档指出:“除非在timeZone中明确指定了时区,否则需要一个时区偏移量”;对于时区,“指定了时间的时区。(格式为IANA时区数据库名称,例如“欧洲/苏黎世” “。)”。

    时区值已正确指定。

    基本上,是否指定时区都没有什么区别。活动是在Google日历的GMT中创建的。
    怎么了

    最佳答案

    修复了它(或者说被黑了)。 Google .Net API包装绝对是垃圾(这是所有API的包装,而不仅仅是Calendar API)。

    问题是event.Startevent.End自动转换日期并在末尾添加“Z”。这告诉Google日期为GMT格式。没有理由加上“Z”,因为即使没有Z,Google也会考虑使用GMT。因此,基本上,因为时间由“Z”附加,所以event.TimeZone=value被忽略。

    删除“Z”后,一切正常。

    entry.Start.DateTimeRaw = replace(entry.Start.DateTimeRaw,"Z","")
    entry.End.DateTimeRaw = replace(entry.End.DateTimeRaw,"Z","")
    

    10-06 05:26
    查看更多