簡體   English   中英

通過Google Calendar API v3創建重復事件

[英]Creating recurring events via Google Calendar API v3

我有一個Web應用程序,用戶可以填寫表單,並在提交后將事件添加到Google日歷。 我可以將事件的單個實例插入日歷,但是當我嘗試設置事件的重復發生時,我無法這樣做。 到目前為止,我的方法沒有完成任何事情,也沒有創建事件,但僅發生一次。

我正在使用下面的Google API日歷v3 ,這是我插入事件的代碼。

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, "********");    
}

編輯1:我重寫了事件創建代碼,如下所示:

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();

唯一的問題是將不會創建該事件,也不會重復發生該事件。 如果我退出該行,則代碼將運行並將單個事件插入日歷。

您忘了調用.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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM