无法使用Java使用日历API创建视频群聊

时间:2020-04-05 22:33:57

标签: java google-calendar-api google-contacts-api

这是代码。

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

1 个答案:

答案 0 :(得分:0)

答案:

由于服务帐户不属于您的域,因此它们无法创建conferenceSolutionhangoutsMeet的日历。

更多信息:

我花了一些时间来理解这一点,但是根据Events resource of the Calendar API的文档,会议解决方案类型如下:

并从Google Cloud Service Account documentation

与用户帐户不同,

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

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

如果您希望日历具有这种会议解决方案类型,则必须创建日历,使其由您的G Suite域成员拥有;也就是说,让服务帐户创建一个模拟为G Suite域成员的日历。

您从Try this API的{​​{1}}功能中获得正确结果的原因是,API调用已获得您的授权-G Suite域用户。

构建服务帐户凭据:

进行身份验证时,需要在构建之前设置要模拟的用户:

Calendars: insert

或带有pk12文件:

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;

希望对您有帮助!

参考文献: