英文:
Can't create a hangoutsMeet with calendar API using Java
问题
以下是代码的翻译部分:
private static Credential authorize() throws Exception {
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
InputStream in = ModuloCalendar.class.getResourceAsStream("quickstart-1585944958709-f0acf97c5fa8.json");
Collection<String> scopes = CalendarScopes.all();
GoogleCredential credential = GoogleCredential.fromStream(in).createScopes(scopes);
return credential;
}
Calendar entry = new Calendar();
entry.setSummary(descripcion);
ConferenceProperties conferenceProperties = new ConferenceProperties();
List<String> allowedConferenceSolutionTypes = new ArrayList<String>();
allowedConferenceSolutionTypes.add("hangoutsMeet");
conferenceProperties.setAllowedConferenceSolutionTypes(allowedConferenceSolutionTypes);
entry.setConferenceProperties(conferenceProperties);
View.display(entry);
Calendar result = client.calendars().insert(entry).execute();
View.display(result);
我已经按照 https://developers.google.com/identity/protocols/oauth2/service-account 上的步骤进行了操作,它创建了日历,但始终返回 "allowedConferenceSolutionTypes":["eventHangout"]
而不是 hangoutsMeet
。
英文:
here is the code.
private static Credential authorize() throws Exception {
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
InputStream in = ModuloCalendar.class.getResourceAsStream("quickstart-1585944958709-f0acf97c5fa8.json");
Collection<String> scopes = CalendarScopes.all();
GoogleCredential credential = GoogleCredential.fromStream(in).createScopes(scopes);
return credential;
}
Calendar entry = new Calendar();
entry.setSummary(descripcion);
ConferenceProperties conferenceProperties=new ConferenceProperties();
List<String> allowedConferenceSolutionTypes = new ArrayList<String>();
allowedConferenceSolutionTypes.add("hangoutsMeet");
conferenceProperties.setAllowedConferenceSolutionTypes(allowedConferenceSolutionTypes);
entry.setConferenceProperties(conferenceProperties);
View.display(entry);
Calendar result = client.calendars().insert(entry).execute();
View.display(result);
I have done steps on https://developers.google.com/identity/protocols/oauth2/service-account
it create the calendar, but it's always return
"allowedConferenceSolutionTypes":["eventHangout"]
Not hangoutsMeet
答案1
得分: 3
答案:
由于服务帐户不是您域的一部分,它们无法创建拥有 conferenceSolution
为 hangoutsMeet
的日历。
更多信息:
我花了一些时间来理解这个问题,根据Calendar API
的Events
资源文档,会议解决方案的类型如下:
> - "eventHangout"
: 适用于消费者的Hangouts (http://hangouts.google.com)
>
> - "eventNamedHangout"
: 适用于G Suite用户的经典Hangouts (http://hangouts.google.com)
>
> - "hangoutsMeet"
: 适用于Hangouts Meet (http://meet.google.com)
>
> - "addOn"
: 适用于第三方会议提供商
从Google云服务帐户文档中可以得知:
> 服务帐户与您的G Suite域不是成员关系,不同于用户帐户。例如,如果您与G Suite域中的所有成员共享资源,则不会与服务帐户共享资源。同样,由服务帐户创建的任何资源都不能由G Suite管理员拥有或管理。
您所遇到的问题是这种情况的结果: 服务帐户不属于您的域,因此无法为自己创建具有 hangoutsMeet
值的会议解决方案类型的日历。
如果您希望日历具有此会议解决方案类型,您必须创建由您G Suite域中的成员拥有的日历;也就是说,使服务帐户以G Suite域成员的身份创建一个日历。
您从Calendars: insert
的Try this API
功能中获得正确结果的原因是API调用被授权为您 - 一个G Suite域用户。
构建服务帐户凭据:
在进行身份验证时,您需要在构建之前设置要模拟的用户:
GoogleCredential.Builder b = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jacksonFactory)
.setServiceAccountId(serviceAccountId)
.setServiceAccountPrivateKey(yourPrivateKey)
.setServiceAccountScopes(scopes)
//在此处指定您要模拟的用户:
.setServiceAccountUser(email-to-impersonate);
credential = b.build();
return credential;
或使用pk12文件:
GoogleCredential.Builder b = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(serviceAccountId)
.setServiceAccountPrivateKeyFromP12File(pk12)
.setServiceAccountScopes(scopes)
//在此处指定您要模拟的用户:
.setServiceAccountUser(email-to-impersonate);
credential = b.build();
return credential;
参考资料:
Calendars: insert
| Google Calendar API | Google Developers- Events | Calendar API | Google Developers
- Understanding service accounts | Cloud IAM Documentation
- Service accounts | Cloud IAM Documentation | Google Cloud
英文:
Answer:
As Service accounts are not part of your domain, they can not create calendars that they own with a conferenceSolution
of hangoutsMeet
.
More Information:
It took me a little while to understand this but, as per the documentation for the Events
resource of the Calendar API, the conference solution types are as follows:
> - "eventHangout"
: for Hangouts for consumers (http://hangouts.google.com)
>
> - "eventNamedHangout"
: for classic Hangouts for G Suite users (http://hangouts.google.com)
>
> - "hangoutsMeet"
: for Hangouts Meet (http://meet.google.com)
>
> - "addOn"
: for 3P conference providers
And from the Google Cloud Service Account documentation:
> Service accounts are not members of your G Suite domain, unlike user accounts. For example, if you share assets with all members in your G Suite domain, they will not be shared with service accounts. Similarly, any assets created by a service account cannot be owned or managed by G Suite admins.
What you're experiencing is a result of this: a Service Account is not part of your domain, and therefore can not create a calendar for itself that has the hangoutsMeet
value for the Conference Solution Type.
If you wish the Calendar to have this conference solution type, you must create the calendar such that it is owned by a member of your G Suite domain; that is to say, have the service account create a calendar impersonating as a member of your G Suite domain.
The reason you are getting the correct result from the Try this API
feature of Calendars: insert
is because the API call is being authorised as you - a G Suite domain user.
Building the Service Account credentials:
When you're doing your authentication you need to set the user that you wish to impersonate before building:
GoogleCredential.Builder b = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jacksonFactory)
.setServiceAccountId(serviceAccountId)
.setServiceAccountPrivateKey(yourPrivateKey)
.setServiceAccountScopes(scopes)
//the user whom you want to impersonate here:
.setServiceAccountUser(email-to-impersonate);
credential = b.build();
return credential;
Or with pk12 file:
GoogleCredential.Builder b = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(serviceAccountId)
.setServiceAccountPrivateKeyFromP12File(pk12)
.setServiceAccountScopes(scopes)
//the user whom you want to impersonate here:
.setServiceAccountUser(email-to-impersonate);
credential = b.build();
return credential;
References:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论