This is my code use case, please refer to it. We are currently logged in with the beem1@beem2023.onmicrosoft.com account. The subscription event "users/{id}/events" is automatically created for the beem2@beem2023.onmicrosoft.com account, and the account beem1 @beem2023.onmicrosoft.com has been granted the Applicationimpersonation permission, but the creation has been unsuccessful and a 400 error has been returned.
{
'error': {
'code': 'ExtensionError',
'message': 'Operation: Create; Exception: [Status Code: BadRequest; Reason: The value 'https://outlook.office365.com/api/v2.0/Users('beem2%40beem2023.onmicrosoft.com') /Events' of parameter 'Resource' is invalid.]',
'innerError': {
'date': '2023-09-21T10:23:51',
'request-id': '472330d7-4ca0-4900-8c00-e4017a9560a4',
'client-request-id': '472330d7-4ca0-4900-8c00-e4017a9560a4'
}
}
}
try {
/**获取当前用户token*/
String outlookAccessToken = outlookCalenderTokenService.getOutlookAccessToken(state, authorizationCode);
for (String userId : userIds) {
/**获取其它用户详情*/
String getUserUrl = outlookCalenderConfig.getGet_user_url().replace("${userPrincipalName}", userId);
Response currentUserResponse = OkHttpUtil.get(getUserUrl, OkHttpUtil.buildAuthorizationMap(outlookAccessToken));
String userResBody = currentUserResponse.body().string();
log.info("state:{} get user info. response:{}.userResBody:{}", state, currentUserResponse, userResBody);
UserDTO userDTO = GSONUtil.fromJson(userResBody, UserDTO.class);
SubscriptionDTO subscription = new SubscriptionDTO();
subscription.setChangeType("created,updated,deleted");
subscription.setNotificationUrl(outlookCalenderConfig.getCallback_url());
/**为其它用户创建订阅事件*/
subscription.setResource("users/"+userDTO.getId()+"/events");
subscription.setExpirationDateTime(OffsetDateTime.now().plusDays(1).toString());
subscription.setClientState(UUID.randomUUID().toString());
subscription.setLatestSupportedTlsVersion("v1_2");
Response response = OkHttpUtil.post(outlookCalenderConfig.getSubscriptions_url(), OkHttpUtil.buildAuthorizationMap(outlookAccessToken), GSONUtil.toJson(subscription));
String subRes = response.body().string();
log.info("【subscription】【code】:{} state:{} subscription:【created,updated】 event. response:{}.subResBody:{}", response.code(), state, response, subRes);
return subRes;
}
} catch (Exception exception) {
}