从电子邮件地址获取Google日历ID

问题描述 投票:1回答:1

我正在使用服务帐户 [email protected]在Google日历上插入新活动。

我无法指定organizercreatorevent。我的代码是:

            Organizer organizer = new Organizer().setEmail("[email protected]").setSelf(true);
            Creator creator = new Creator().setEmail("[email protected]").setSelf(true);

            Calendar service = Calendar_Utils.getCalendarService();
            Event event = new Event()
                         .setSummary("Google Calendar API")
                         .setOrganizer(organizer)
                         .setCreator(creator);

            DateTime startDateTime = new DateTime("2020-04-24T09:00:00.000Z");
            EventDateTime start = new EventDateTime()
                                  .setDateTime(startDateTime)
                                  .setTimeZone("Africa/Tunis");
            event.setStart(start);

            DateTime endDateTime = new DateTime("2020-04-24T10:30:00.000Z");
            EventDateTime end = new EventDateTime()
                                .setDateTime(endDateTime)
                                .setTimeZone("Africa/Tunis");
            event.setEnd(end);

            String calendarId = "primary";
            event = service.events().insert(calendarId, event).execute();
            System.out.printf("Event created: %s\n", event.getHtmlLink() + " - " + event.getOrganizer() + " - " + event.getCreator());

因此,将插入新事件,但插入的是组织者和创建者[email protected],而不是[email protected]

您能告诉我如何更改代码以将组织者设置为[email protected]

非常感谢。

java google-api google-calendar-api google-api-java-client service-accounts
1个回答
0
投票

默认情况下,执行events.patch并更新Event上的组织者字段,组织者属性设置为创建事件的人员或服务帐户。

© www.soinside.com 2019 - 2024. All rights reserved.