我在我最近添加了国家云支持的应用程序中使用了 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);
。但是,这适用于全局端点。可能是什么问题?