java - Microsoft Graph List 将 API 与 National Cloud 端点
问题描述
我在我最近添加了国家云支持的应用程序中使用了 microsoft graph API。美国环境的身份验证成功,但列表位置 API 似乎不适用于国家云端点。
private final static String NATIONAL_CLOUD_US_L4="US-L4";
private final static String NATIONAL_CLOUD_US_L5_DOD="US-L5 (DOD)";
private final static String NATIONAL_CLOUD_CHINA="China";
private final static String NATIONAL_CLOUD_GERMANY="Germany";
private final static String GET_ROOMS_GLOBAL = "https://graph.microsoft.com/v1.0/places/microsoft.graph.room?$top=5000";
private final static String GET_ROOMS_US_L4 = "https://graph.microsoft.us/v1.0/places/microsoft.graph.room?$top=5000";
private final static String GET_ROOMS_US_L5_DOD = "https://dod-graph.microsoft.us/v1.0/places/microsoft.graph.room?$top=5000";
private final static String GET_ROOMS_CHINA = "https://microsoftgraph.chinacloudapi.cn/v1.0/places/microsoft.graph.room?$top=5000";
private final static String GET_ROOMS_GERMANY = "https://graph.microsoft.de/v1.0/places/microsoft.graph.room?$top=5000";
private void setNationalCloudUrl(String country) {
switch(country) {
case NATIONAL_CLOUD_US_L4:
GET_ROOMS_URL=GET_ROOMS_US_L4;
break;
case NATIONAL_CLOUD_US_L5_DOD:
GET_ROOMS_URL=GET_ROOMS_US_L5_DOD;
break;
case NATIONAL_CLOUD_GERMANY:
SCOPE = SCOPE_GERMANY;
AUTHORITY_URL=AUTHORITY_URL_GERMANY;
GET_ROOMS_URL=GET_ROOMS_GERMANY;
break;
case NATIONAL_CLOUD_CHINA:
GET_ROOMS_URL=GET_ROOMS_CHINA;
break;
default:
GET_ROOMS_URL=GET_ROOMS_GLOBAL;
break;
}
}
public ResourceProfilesDto retrieveAllResourceProfiles() {
ResourceProfilesDto profilesDto = new ResourceProfilesDto();
List<ResourceProfileDto> profileDtos = new ArrayList<>();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
try {
String accessToken = getAccessToken();
headers.set(AUTHORIZATION, "Bearer " + accessToken);
HttpEntity entity = new HttpEntity(headers);
ResponseEntity<GraphResourceProfileResponse> response = restTemp.exchange(GET_ROOMS_URL, HttpMethod.GET,
entity, GraphResourceProfileResponse.class);
for (GraphResourceProfile graphResource : response.getBody().getValue()) {
ResourceProfileDto resourceProfileDto = new ResourceProfileDto();
resourceProfileDto.setExternalId(graphResource.getEmailAddress());
resourceProfileDto.setHashedExternalId(DigestUtils.sha256Hex(graphResource.getEmailAddress()));
resourceProfileDto.setFriendlyName(graphResource.getDisplayName());
profileDtos.add(resourceProfileDto);
}
profileDtos.sort((p1, p2) -> p1.getFriendlyName().compareTo(p2.getFriendlyName()));
profilesDto.getProfileList().addAll(profileDtos);
}catch(GraphServiceException ex) {
try {
if(ex.getMessage().contains(ACCESS_TOKEN_EXPIRED)) {
configurationService.putSecureString(ACCESS_TOKEN, "");
getAccessToken();
return retrieveAllResourceProfiles();
}
profileDtos = null;
}catch(Exception exception) {
log.error("Exception occurred while retrieveAllResourceProfiles(retry). ERROR is : {}", exception);
profileDtos = null;
}
} catch (Exception e) {
log.error("Error trying to retrieve resource profiles.", e);
profileDtos = null;
}
return profilesDto;
}
我收到org.springframework.web.client.HttpClientErrorException: 400 Bad Request
这条线的错误ResponseEntity<GraphResourceProfileResponse> response = restTemp.exchange(GET_ROOMS_URL, HttpMethod.GET,entity, GraphResourceProfileResponse.class);
。但是,这适用于全局端点。可能是什么问题?
解决方案
推荐阅读
- javascript - 如何在 piral app-shell 和 pilet 应用程序中使用 styled-components?
- asp.net-core-webapi - 会话存储在 asp.net 核心 web api 中返回 null
- javascript - 复选框返回 null
- mongodb - 使用 FindOne 和 $natural 从 GoLang 中的 mongodb 获取最后插入的元素
- python - 无法安装 Ball 模块
- powershell - 如何在powershell中返回具有相同扩展名但包含特定名称结尾的文件?
- amazon-web-services - 在 Terraform 中使用模块将 EIP 关联到我的 NAT 网关后出现错误
- python-3.x - 使用给出错误“ValueError:加密/解密失败”的加密包解密数据。
- json - 尝试将 JSON 文件加载到数据框中时出现 UnicodeDecodeError
- date - 从日期中减去的正确顺序是什么