创建Google日历“提醒”时出错

时间:2010-04-14 08:16:56

标签: c# google-calendar-api

我使用下面的代码在Google日历中创建提醒(使用Google API ver 2 for c#):

    EventEntry entry = new EventEntry();

    entry.Title.Text = "testing from .NET";
    entry.Content.Content = "testing from .NET";

    String recurData =
   "DTSTART;TZID=America/Los_Angeles:20071202T080000\r\n" +
   "DTEND;TZID=America/Los_Angeles:20071202T090000\r\n" +
   "RRULE:FREQ=WEEKLY;WKST=SU;UNTIL=20071230T160000Z;BYDAY=SU\r\n";

   Recurrence recurrence = new Recurrence();
   recurrence.Value = recurData;
   entry.Recurrence = recurrence;

   Reminder reminder = new Reminder();
   reminder.Minutes = 15;
   reminder.Method = Reminder.ReminderMethod.all;   
   entry.Reminders.Add(reminder);

获取错误:对象引用未设置为对象的实例。

感谢名单

3 个答案:

答案 0 :(得分:1)

条目是否存在?如果是这样,提醒是否存在? (我的意思是两个都不是NULL)

从api link判断。在设置提醒之前,您必须将事件添加到日历中:

Uri postUri = new Uri("http://www.google.com/calendar/feeds/default/private/full");
EventEntry createdEntry = (EventEntry) service.Insert(postUri, myEntry);
//and then add reminders

see this

注意我没有使用Google API,因此我无法保证它是否有效。您应该调试应用程序并查看EventEntry和Reminders的值

答案 1 :(得分:1)

CalendarEventEntry saveEntry = myService.insert(eventFeedUrl, entry);

saveEntry.getReminder().add(reminder);

*提示必须在插入/更新操作后添加

答案 2 :(得分:0)

您应该完成“条目”对象的更新。 使用 entry.Update() 设置提醒对象后.. 希望这会有所帮助..