热门标签 | HotTags
当前位置:  开发笔记 > 开放平台 > 正文

SpringWebclient:非法参数异常没有足够的变量来扩展'comment_count'

如何解决《SpringWebclient:非法参数异常没有足够的变量来扩展'comment_count'》经验,为你挑选了1个好方法。

我正在使用spring webclient发出带有{comment_count}的url的Facebook图形api请求

但是,得到这个例外

java.lang.IllegalArgumentException: Not enough variable values available to expand reactive spring

代码段:

import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;

import reactor.core.publisher.Mono;

@Component
public class Stackoverflow {

    WebClient client = WebClient.create();

    public Mono fetchPost(String url) {
        // Url contains "comments{comment_count}"
        return client.get().uri(url).retrieve()
                .bodyToMono(Post.class);
    }
}

我知道resttemplate的解决方案,但是我需要使用spring webclient。



1> yash sugandh..:

您可以使用UriComponentsBuilder创建URL,如下所示

 webClient.get().uri(getFacebookGraphURI(3)).retrieve().bodyToMono(Object.class);

private URI getFacebookGraphURI(int comments){
   return UriComponentsBuilder.fromHttpUrl("https://graph.facebook.com")
        .pathSegment("v3.2", "PAGE_ID", "posts").queryParam("fields", "comments{comment_count}")
        .queryParam("access_token", "acacaaac").build(comments);

  }

要么

int commentsCount = 3; webClient.get()。uri(UriComponentsBuilder.fromHttpUrl(“ https://graph.facebook.com ”).pathSegment(“ v3.2”,“ PAGE_ID”,“帖子”).queryParam(“ fields”,“评论{comment_count}“).queryParam(” access_token“,” acacaaac“)。build()。toString(),commentsCount).retrieve()。bodyToMono(Object.class);


推荐阅读
author-avatar
姚若薇_453
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有