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.
Did you forget to call .execute() ?
Event newEvent = new Event()
{
Summary = "Read Awesome Blog posts by Linda ",
Location = "1600 Amphitheatre Parkway., Mountain View, CA 94043",
Description = "A chance to learn more about Google APIs.",
Start = new EventDateTime()
{
DateTime = DateTime.Parse("2015-09-20T09:00:00-07:00"),
TimeZone = "America/Los_Angeles",
},
End = new EventDateTime()
{
DateTime = DateTime.Parse("2015-09-20T17:00:00-07:00"),
TimeZone = "America/Los_Angeles",
},
Recurrence = new String[] { "RRULE:FREQ=DAILY;COUNT=2" },
Attendees = new EventAttendee[] {
new EventAttendee() { Email = "test@test.com" },
},
Reminders = new Event.RemindersData()
{
UseDefault = false,
Overrides = new EventReminder[] {
new EventReminder() { Method = "email", Minutes = 24 * 60 },
new EventReminder() { Method = "sms", Minutes = 10 },
}
}
};
String calendarId = "primary";
EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
Event createdEvent = request.Execute();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.