问题
So far I am able to insert an event in a calendar using the following code.
Dim calService As CalendarService = calendarFunctions.getCalendarService(txtrefreshToken.Text.Trim)
Dim calEventEntry As New Data.Event
calEventEntry.Summary = "Invoice #123456 Due on dd/mm/yyyy"
calEventEntry.Description = "Client: Acme Printing Ltd."
calEventEntry.Id = "inv5670010"
Dim eventStartDT As New Data.EventDateTime()
eventStartDT.DateTime = DateTime.Now.AddHours(24)
Dim eventStartEndDT As New Data.EventDateTime()
eventStartEndDT.DateTime = DateTime.Now.AddHours(25)
calEventEntry.Start = eventStartDT
calEventEntry.End = eventStartEndDT
Dim er As New EventsResource(calService)
Dim erResp As Data.Event = er.Insert(calEventEntry, txtactiveCal.Text.Trim).Execute()
'SO FAR SO GOOD!
'Add email reminder to event
Dim remR As New EventReminder()
remR.Method = "email"
remR.Minutes = 10
erResp.Reminders.Overrides.Add(remR) ' <<< ERROR: Object reference not set to an instance of an object
In the last block I am trying to add the reminder to the event (I unserstand this must be done after the event has been created?) . On the last line I get the following error:
Object reference not set to an instance of an object
Does anyone know what I'm doing wrong here?
回答1:
I would suspect Overrides to be null by default so you can't add anything in there unless you initialize them.
回答2:
I solved this in the end by creating a List(of EventReminder)
object adding the desired reminder and binding this to the Overrides
property for event.reminders
. Hopefully this code may be of help to others.
Dim eventReminder As New List(Of EventReminder)()
eventReminder.Add(New EventReminder() With { _
.Minutes = 10, _
.Method = "email" _
})
Dim de As New Data.Event.RemindersData()
de.UseDefault = False
de.[Overrides] = eventReminder
calEventEntry.Reminders = de
Dim er As New EventsResource(calService)
Dim erResp As Data.Event = er.Insert(calEventEntry, txtactiveCal.Text.Trim).Execute()
Response.Write("Event ID: " & erResp.Id & "<br/>")
Response.Write("Link: <a href=""" & erResp.HtmlLink & """>" & erResp.HtmlLink & "</a><br/>")
来源:https://stackoverflow.com/questions/24234296/google-calender-vr3-how-do-i-add-a-reminder-to-an-event