[英]get google calendar id from an email address
I'm inserting a new event on Google Calendar using a service account service@entreprise.tn
.我正在使用服务帐户
service@entreprise.tn
在 Google 日历上插入一个新事件。
I can't specify the organizer
or the creator
of an event
.我无法指定活动的
organizer
或creator
event
My code is:我的代码是:
Organizer organizer = new Organizer().setEmail("user1@entreprise.tn").setSelf(true);
Creator creator = new Creator().setEmail("user1@entreprise.tn").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());
As result, the new event is inserted, but with organizer and creator service@entreprise.tn
and not user1@entreprise.tn
.结果,插入了新事件,但组织者和创建者是
service@entreprise.tn
而不是user1@entreprise.tn
。
Could you please tell me how can I change my code to set the organizer to user1@entreprise.tn
.你能告诉我如何更改我的代码以将组织者设置为
user1@entreprise.tn
?
Thanks a lot.非常感谢。
Do an events.patch and update the organizer fields on the Event by default the organizer property is set to the person or service account which created the event.默认情况下,执行events.patch并更新事件上的组织者字段,组织者属性设置为创建事件的人员或服务帐户。
If the service account has been set up with domain wide delegation to a gsuie domain you can impersonate one of the users on the domain and the organizer will be the user who was impersonated.如果服务帐户已设置为在域范围内委派给 gsuie 域,您可以模拟该域中的其中一个用户,组织者将是被模拟的用户。
In Java you would do it as following:在 Java 中,您可以按以下方式进行操作:
GoogleCredential getCredentials = new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(serviceAccount)
.setServiceAccountPrivateKeyFromP12File(pk12)
.setServiceAccountScopes(SCOPES)
.setServiceAccountUser("user1@entreprise.tn")
.build();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.