2

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.

2
  • remove this ev.RecurringEventId = "asdf" + rnd.Next(9999).ToString(); Commented Sep 23, 2015 at 6:31
  • @DaImTo Even with that removed it doesn't work. I had tried putting that in place to see if that was what was missing. Commented Sep 23, 2015 at 13:09

1 Answer 1

4

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 = "[email protected]" },
                },
                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();
Sign up to request clarification or add additional context in comments.

2 Comments

I can leave off the recurrence line of code and it will create the event on my calendar, but when it is included the event will not be added nor will its recurrence.
Ok I'm not sure what I did differently but it now works after deleting everything and starting over. Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.