使用Google Calendar API在会议室日历上创建活动时出错

时间:2019-09-19 16:17:08

标签: google-api google-api-client google-api-java-client

我正在开发一个使用Google Calendar API插入/更新/删除Google Calendar事件的应用程序。 我正在使用oauth2身份验证,并且已在我的Google项目中启用了日历API。 这是我的代码:

JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
String TOKENS_DIRECTORY_PATH = "PATH_TOKEN";

String appName = "APP_NAME"
String clientId = "CLIENT_ID";
String clientSecret = "CLIENT_SECRET";

String token = "{\"installed\":{\"client_id\":\"" + clientId + "\",\"client_secret\":\"" + clientSecret +"\"}}";
InputStream in = new ByteArrayInputStream(token.getBytes(StandardCharsets.UTF_8));

GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();

// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, Collections.singletonList(CalendarScopes.CALENDAR_EVENTS)).setDataStoreFactory(new FileDataStoreFactory(TOKENS_DIRECTORY_PATH) + TOKENS_DIRECTORY_PATH))).setAccessType("offline").build();

Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");

// Build a new authorized API client service.
service = new Calendar.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(appName).build();

Event appointment = new Event();
... // creation event

service.events().insert("MAIL_ROOM", appointment).setSendNotifications(true).execute();

我可以在用户日历中插入/更新/删除事件,但是如果尝试在Google会议室中插入事件,则会出现此错误:

403 prohibited
{
"code": 403,
"mistakes" : [ {
"domain": "calendar",
"message": "You must have author access to this calendar.",
"reason": "requiredAccessLevel"
}],
"message": "You must have access as a writer to this calendar."
}.

我可以更新和删除Google会议室日历上的事件,但无法创建事件。 Google Calendar API是否受到限制,或者是否可以在会议室的日历上创建活动?

谢谢

0 个答案:

没有答案