Код: Выделить всё
{"error":"unsupported_grant_type","error_description":"grant_type parameter is missing"}Это мой код:
Код: Выделить всё
public static void getAuthToken() throws Exception {
Gson gson = new Gson();
Transcript transcript = new Transcript();
String jsonRequest = gson.toJson(transcript);
String originalInput = Access.CLIENT_ID + ":" + Access.CLIENT_SECRET;
String encodedString = Base64.getEncoder().encodeToString(originalInput.getBytes());
System.out.println(jsonRequest);
HttpRequest postRequest = (HttpRequest) HttpRequest.newBuilder()
.uri(new URI("https://accounts.spotify.com/api/token"))
.POST(HttpRequest.BodyPublishers.ofString(jsonRequest))
.header("Authorization", "Basic " + encodedString)
.header("Content-Type", "application/x-www-form-urlencoded")
.build();
HttpClient httpClient = HttpClient.newHttpClient();
HttpResponse postResponse = httpClient.send(postRequest, HttpResponse.BodyHandlers.ofString());
System.out.println(postResponse.body());
}
< /code>
и: < /p>
public class Transcript {
private String grant_type = "client_credentials";
}
Подробнее здесь: https://stackoverflow.com/questions/744 ... -with-java