我正在尝试与 Instagram 的 API 通信,但我从我的请求中得到的回复说我传递给身体的参数没有被检测到。
{"error_type":"OAuthException","code":400,"error_message":"You must provide a client_id"}
我尝试通过在 .post() 中传递 JsonNode 或字符串来发送请求,如下所示,但两者均不成功。
public CompletionStage<Result> getInstagramToken() {
String code = request().getQueryString("code");
if(code != null) {
WSRequest request = ws.url("https://api.instagram.com/oauth/access_token").setContentType("application/x-wwww-form-urlencoded");
// Json body
/*JsonNode body = Json.newObject()
.put("client_id", insta_clientId)
.put("client_secret", insta_clientSecret)
.put("grant_type", "authorization_code")
.put("redirect_uri", redirect_uri)
.put("code", code);*/
// String body
String body = "client_id="+insta_clientId+"&client_secret="+insta_clientSecret+"&grant_type=authorization_code&redirect_uri="+redirect_uri+"&code="+code;
CompletionStage<WSResponse> response = request.post(body);
return response.thenApplyAsync(resp -> ok(resp.asJson()), exec);
}
return null;
}
尝试通过在终端上使用 curl 命令或使用 chrome 上的 Rested 插件(其中“内容类型”设置为“应用程序/x-www-form-urlencoded”并放置参数)时,相同的请求完美传递在“请求正文”内)
有谁知道我应该如何发送这个请求?
ps:我也在寻找一种方法来检索从我的请求中收到的值并将其存储在一个变量中,而不是将其返回给客户端。