设置Google日历提醒—从API v2迁移到API v3



之前,我有以下可行的Google Calendar API 2

Google Calendar API v2

    CalendarEventEntry calendarEventEntry = new CalendarEventEntry();
    calendarEventEntry.setTitle(new PlainTextConstruct(message));
    calendarEventEntry.setContent(new PlainTextConstruct(message));
    calendarEventEntry.addTime(when);
    // 0 minute reminder
    Reminder reminder = new Reminder();
    reminder.setMinutes(0);
    reminder.setMethod(Method.SMS);
    List<Reminder> reminders = calendarEventEntry.getReminder();
    reminders.add(reminder);
    // Send the request and receive the response:
    try {
        calendarEventEntry = calendarService.insert(postUrl, calendarEventEntry);
    } catch(IOException exp) {
        log.error(null, exp);
        return false;
    } catch (ServiceException exp) {
        log.error(null, exp);
        return false;
    }
    return true;

现在,我想迁移到Google Calendar API v3

    // Create a new event.
    Event event = new Event();
    event.setSummary(message);
    event.setStart(startEventDateTime);
    event.setEnd(endEventDateTime);
    // 0 minute reminder
    EventReminder reminder = new EventReminder();
    reminder.setMinutes(0);
    reminder.setMethod("sms");
    List<EventReminder> listEventReminder = new ArrayList<EventReminder>();
    listEventReminder.add(reminder);
    System.out.println("Is null? = " + event.getReminders());
    event.getReminders().setOverrides(listEventReminder);
    try {
        Event createdEvent = service.events().insert(calendarListEntry.getId(), event).execute();
    } catch (IOException ex) {
        log.error(null, ex);
        return false;
    }
    return true;

但是,event.getReminders总是返回null。我想知道,正确的做法是什么?

如果您感兴趣,我将完整的代码集放在GitHub: googleccalendar .java

仅通过查看API,您是否尝试过此操作?

Event.Reminders reminders = new Event.Reminders();
reminders.setUseDefault(false);
List<EventReminder> listEventReminder = new ArrayList<EventReminder>();
listEventReminder.add(reminder);
reminders.setOverrides(listEventReminder);
event.setReminders(reminders);
System.out.println("Is null? = " + event.getReminders());

在API 3的当前版本(rev85=1.18-rc)提醒只接受PRIMARY日历。为其他日历设置提醒被忽略——你得到默认值。无错误信息,无文档

相关内容

  • 没有找到相关文章

最新更新