无法使用Java创建Hangouts Meet与日历API。

huangapple go评论76阅读模式
英文:

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(&quot;quickstart-1585944958709-f0acf97c5fa8.json&quot;);  
	  
    Collection&lt;String&gt; scopes  = CalendarScopes.all();
	  
    GoogleCredential credential = GoogleCredential.fromStream(in).createScopes(scopes);
    return credential;
}
Calendar entry = new Calendar();
entry.setSummary(descripcion);

ConferenceProperties conferenceProperties=new ConferenceProperties();

List&lt;String&gt; allowedConferenceSolutionTypes = new ArrayList&lt;String&gt;();

allowedConferenceSolutionTypes.add(&quot;hangoutsMeet&quot;);

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
&quot;allowedConferenceSolutionTypes&quot;:[&quot;eventHangout&quot;]

Not hangoutsMeet

答案1

得分: 3

答案:

由于服务帐户不是您域的一部分,它们无法创建拥有 conferenceSolutionhangoutsMeet 的日历。

更多信息:

我花了一些时间来理解这个问题,根据Calendar APIEvents资源文档,会议解决方案的类型如下:

> - &quot;eventHangout&quot;: 适用于消费者的Hangouts (http://hangouts.google.com)
>
> - &quot;eventNamedHangout&quot;: 适用于G Suite用户的经典Hangouts (http://hangouts.google.com)
>
> - &quot;hangoutsMeet&quot;: 适用于Hangouts Meet (http://meet.google.com)
>
> - &quot;addOn&quot;: 适用于第三方会议提供商

Google云服务帐户文档中可以得知:

> 服务帐户与您的G Suite域不是成员关系,不同于用户帐户。例如,如果您与G Suite域中的所有成员共享资源,则不会与服务帐户共享资源。同样,由服务帐户创建的任何资源都不能由G Suite管理员拥有或管理。

您所遇到的问题是这种情况的结果: 服务帐户不属于您的域,因此无法为自己创建具有 hangoutsMeet 值的会议解决方案类型的日历。

如果您希望日历具有此会议解决方案类型,您必须创建由您G Suite域中的成员拥有的日历;也就是说,使服务帐户以G Suite域成员的身份创建一个日历。

您从Calendars: insertTry 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;

参考资料:

英文:

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:

> - &quot;eventHangout&quot;: for Hangouts for consumers (http://hangouts.google.com)
>
> - &quot;eventNamedHangout&quot;: for classic Hangouts for G Suite users (http://hangouts.google.com)
>
> - &quot;hangoutsMeet&quot;: for Hangouts Meet (http://meet.google.com)
>
> - &quot;addOn&quot;: 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:

huangapple
  • 本文由 发表于 2020年4月6日 06:33:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/61050432.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定