以下是我用于类似项目的一些代码片段。我使用了 google api 和 .net 框架,这比使用 OAuth 更容易。这些片段在 Visual Basic 中
Imports Google.GData
Imports Google.GData.Client
Imports Google.GData.Calendar
.....Various Property Fields for the class go here.....
Public Sub AddEvent()
Try
Dim theEvent As New EventEntry
Dim theCalendarService As CalendarService = New CalendarService(FProgID)
Dim theTime As New Extensions.When(FEventStartTime, FEventEndTime)
Dim theEntry As AtomEntry
If FAllDay = True Then
theTime.AllDay = True
Else
theTime.AllDay = False
End If
theEvent.Title.Text = FEventTitle
theEvent.Times.Add(theTime)
If Not FDescription = "" Then
theEvent.Content.Content = FDescription
End If
If Not FEventLocation = "" Then
Dim theLocation As New Extensions.Where
theLocation.ValueString = FEventLocation
theEvent.Locations.Add(theLocation)
End If
If Not FAuthor = "" Then
Dim theAuthor As New AtomPerson
theAuthor.Name = FAuthor
theEvent.Authors.Add(theAuthor)
End If
theCalendarService.setUserCredentials(FstrEmail, FstrPassword)
theEntry = theCalendarService.Insert(FURLNoCookie, theEvent)
FStatus = "Event added successfully to Google Calendar"
Catch ex As Exception
FStatus = "Failed: Event was added to Job List, but not Google Calendar"
End Try
End Sub
总之,我只是使用谷歌为 .net 框架提供的日历服务类。FstrEmail 只是与日历关联的电子邮件地址,而 FstrPassword 是常规的 google 密码。FURLNoCookie 实际上是您指定它去往哪个日历的地方。这只是日历的 XML 私人共享 URL(从日历设置>私人地址获取)。当您第一次从日历中获取此 URL 时,它看起来像这样
http://www.google.com/calendar/feeds/somebody%40gmail.com/private-188ba1932aa23d4a64ag712db232bfe8b/basic
修改它看起来像这样
http://www.google.com/calendar/feeds/somebody%40gmail.com/private/full
类似的过程可用于更新和删除条目。我用它来同步电子表格与多个谷歌日历,它工作正常。