【问题标题】:Error in creating Google Calendar "Reminder"创建 Google 日历“提醒”时出错
【发布时间】:2010-04-14 08:16:56
【问题描述】:

我正在使用以下代码在 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);

出现错误:对象引用未设置为对象的实例。

感谢

【问题讨论】:

    标签: c# google-calendar-api


    【解决方案1】:

    条目是否存在?如果有,是否存在提醒? (我的意思是两者都不为 NULL)

    从apilink来看。您必须在设置提醒之前将事件添加到日历中:

    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 的值

    【讨论】:

    • 我正在创建条目。但是如何创建提醒?我认为这(如 post 中所述)是创建提醒的唯一方法。
    • 条目的 Reminders 对象是否存在,因为您向它添加了一个提醒对象。你能发布一些你如何创建条目的代码吗?
    • 你不能在抛出错误的行上设置一个断点并检查条目或提醒(如果已设置)。条目似乎已设置,否则每次使用时都会出错。也许是别的东西,请参阅更新后的帖子
    【解决方案2】:
    CalendarEventEntry saveEntry = myService.insert(eventFeedUrl, entry);
    
    saveEntry.getReminder().add(reminder);
    

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

    【讨论】:

    • 请正确格式化您的代码,请单击问题或答案文本框中的orange question mark 以获得解释。谢谢!
    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 2017-01-28
      • 2015-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多