So I'm trying to get the access token for the Web API with the client_id and client_secret, but I'm keep getting this error: {"error":"unsupported_grant_type","error_description":"grant_type parameter is missing"} This is my code: `
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<String> postResponse = httpClient.send(postRequest, HttpResponse.BodyHandlers.ofString());
System.out.println(postResponse.body());
}
and:
public class Transcript {
private String grant_type = "client_credentials";
}
`
Well the error obviously states that something is wrong with the grant_type, so I printed the request body and it seems fine.