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

我祈祷:

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

我不能指定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]

非常感谢。

ziganotschka:

使用服务帐户创建事件时,需要模拟要创建事件的用户

在Java中,您可以按照以下步骤进行操作:

    GoogleCredential getCredentials = new GoogleCredential.Builder()
     .setTransport(HTTP_TRANSPORT)
     .setJsonFactory(JSON_FACTORY)
     .setServiceAccountId(serviceAccount)
     .setServiceAccountPrivateKeyFromP12File(pk12)
     .setServiceAccountScopes(SCOPES)
     .setServiceAccountUser("[email protected]") 
     .build();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章