带有嵌套投影的uribuilder在java.lang中失败illegalargumentexceptionMap没有“shares{id,link”的值

guykilcj  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(195)

我有一个用例来获取现有的 share 来自fb graph api的消息元数据,我正在使用这些字段 fields=updated_time,messages{message,id,created_time,from,to,tags,attachments,shares{id,link} 现有实现:用于此urlhttps://graph.facebook.com/v5.0/me/conversations?fields=updated_time,messages{message,id,created\u time,from,to,tags,attachments,sticker}我们在buildermap中插入值,如下所示

builderMap.put("message,id,created_time,from,to,tags,attachments,sticker",
                    "{message,id,created_time,from,to,tags,attachments,sticker}");

UriBuilder builder =  new DefaultUriBuilderFactory(baseURL).builder();
uri = builder.build(builderMap);

webClient.get()
    .uri(uri)
    .retrieve()
    .onStatus(HttpStatus::isError, (clientResponse) -> {
            return this.handleError(clientResponse, errorType, exceptionTransformer);
    }).bodyToMono(responseType).block();

新实施:

uriBuilderMap.put("message,id,created_time,from,to,tags,attachments,sticker,shares{id,link}","{message,id,created_time,from,to,tags,attachments,sticker,shares{id,link}}");

uriBuilderMap.put("id,link", "{id,link}");
UriBuilder builder =  new DefaultUriBuilderFactory(baseURL).builder();
uri = builder.build(builderMap);

webClient.get()
    .uri(uri)
    .retrieve()
    .onStatus(HttpStatus::isError, (clientResponse) -> {
            return this.handleError(clientResponse, errorType, exceptionTransformer);
    }).bodyToMono(responseType).block();

例外情况:

java.lang.IllegalArgumentException: Map has no value for 'message,id,created_time,from,to,tags,attachments,sticker,shares{id,link'
    at org.springframework.web.util.UriComponents$MapTemplateVariables.getValue(UriComponents.java:345)
    at org.springframework.web.util.HierarchicalUriComponents$QueryUriTemplateVariables.getValue(HierarchicalUriComponents.java:1055)
    at org.springframework.web.util.UriComponents.expandUriComponent(UriComponents.java:262)
    at org.springframework.web.util.HierarchicalUriComponents.lambda$expandQueryParams$5(HierarchicalUriComponents.java:443)
    at java.util.Map.forEach(Map.java:630)

如何处理这种嵌套投影 https://graph.facebook.com/v5.0/me/conversations?fields=updated_time,messages{message,id,created_time,from,to,tags,attachments,shares{id,link},sticker} ?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题