Spotify API Authtoken с JavaJAVA

Программисты JAVA общаются здесь
Anonymous
Spotify API Authtoken с Java

Сообщение Anonymous »

Итак, я пытаюсь получить токен доступа для веб -API с client_id и client_secret, но я продолжаю получать эту ошибку: < /p>

Код: Выделить всё

{"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";

}
Ну, ошибка, очевидно, гласит, что с Grant_type что -то не так.>

Подробнее здесь: https://stackoverflow.com/questions/744 ... -with-java

Вернуться в «JAVA»