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

时间:2014-05-03 12:11:05

标签: java google-api google-calendar-api

以前,我有以下可行的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上:GoogleCalendar.java

2 个答案:

答案 0 :(得分:3)

只要查看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());

答案 1 :(得分:1)

在当前版本的API 3(rev85 = 1.18-rc)中,只接受PRIMARY日历的提醒。忽略设置其他日历的提醒 - 您将获得默认值。 没有错误消息,没有文档。