I've got a web application that a user fills out a form and on submit it adds an event to a google calendar. I can insert a single instance of an event onto the calendar but when I try to set the recurrence of the event I am unable to do so. My methods so far have either accomplished nothing or the event is created, but only for a single occurrence.
I am using google api calendar v3 below is my code to insert the event.
try{
Google.Apis.Calendar.v3.CalendarService g = new
Google.Apis.Calendar.v3.CalendarService();
Google.Apis.Calendar.v3.Data.Event ev = new
Google.Apis.Calendar.v3.Data.Event();
//Create Date Times for start and end time
EventDateTime starter = new EventDateTime();
starter.DateTime = start;
EventDateTime ender = new EventDateTime();
ender.DateTime = end;
//Add values to the event
ev.Start = starter;
ev.End = ender;
ev.Summary = summary.Text;
ev.Location = location.Text;
ev.Description = description.Text;
String[] recd = {"RRULE:FREQ=WEEKLY;COUNT=2"};
Random rnd = new Random();
ev.RecurringEventId = "asdf" + rnd.Next(9999).ToString();
ev.Recurrence = recd;
//Add to calendar
addEvent(service, ev);
g.Events.Insert(ev, "********");
}
EDIT 1: I've rewritten my event creation code as follows:
EventDateTime starter = new EventDateTime();
starter.DateTime = start;
EventDateTime ender = new EventDateTime();
ender.DateTime = end;
Event newEvent = new Event()
{
Summary = summary.Text,
Location = location.Text,
Description = description.Text,
Start = starter,
End = ender,
Recurrence = new String[] {"RRULE:FREQ=DAILY;COUNT=2"}
};
String calendarId = "****@group.calendar.google.com";
EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
Event createdEvent = request.Execute();
The only problem being that the event will not be created nor its recurrence. If I leave off that line, the code will run and insert the single event into the calendar.