I am trying to exchange my authorizatoin code for an access token. I keep getting a "request parameters are malformed" error. I can curl the endpoint just fine but for some reason I can't get a valid response in the server.
Here is the code I am using:
public TikTokTokenResponse getTiktokAccessToken(String code, String redirectUrl) throws Exception {
URI uri = new URI(String.format("https://open.tiktokapis.com/v2/oauth/token/"));
MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
body.add("client_key", tiktokClientKey);
body.add("client_secret", tiktokClientSecret);
body.add("code", code);
body.add("grant_type", "authorization_code");
body.add("redirect_uri", redirectUrl);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.setCacheControl("no-cache");
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers);
log.info("Getting tiktok access token " + uri.toString());
return restTemplate.postForObject(uri, requestEntity, TikTokTokenResponse.class);
}