【发布时间】:2021-12-25 18:44:13
【问题描述】:
我正在尝试遍历分页的帐户列表,但是当我使用“next_uri”中的值发送请求时,我收到来自服务器的错误: {"errors":[{"id":"not_found","message":"Not found"}]}
我正确地添加了标头等,因为所有其他 API 调用都可以正常工作,它只是使用“next_uri”的请求不起作用。我认为我正确地遵循了 api 规范,所以我不确定问题是什么以及如何解决它。请问有人知道代码/逻辑有什么问题吗?
简化代码:
ArrayList<X> results = new ArrayList<>();
String uri = "/v2/accounts";
javax.ws.rs.client.Client client = getClient();
while(uri != null){
T response = client.target("https://api.coinbase.com")
.path(uri).request(MediaType.APPLICATION_JSON).get(responseType);
results.addAll(response.getData());
uri = response.getPagination()==null ? null :response.getPagination().getNextUri();
}
return results;
结果是这样的:
请求 1:
响应 1:分页“:
{"ending_before":null,"starting_after":null,"previous_ending_before":null,"next_starting_after":"ef35df6c-a45b-5858-b755-f12a709cf26e","limit":25,"order":"desc ","previous_uri":null,"next_uri":"/v2/accounts?starting_after=ef35df6c-a45b-5858-b755-f12a709cf26e"},"data":[{....} ]
请求 2:
https://api.coinbase.com/v2/accounts%3Fstarting_after=ef35df6c-a45b-5858-b755-f12a709cf26e
响应 2:
{"errors":[{"id":"not_found","message":"未找到"}]}
【问题讨论】:
标签: java jax-rs resteasy coinbase-api