Java Spotify Web API+;身份验证客户端凭据流

Java Spotify Web API+;身份验证客户端凭据流,java,rest,spotify,spring-web,Java,Rest,Spotify,Spring Web,我是Spotify Web API的新手,在通过客户端凭据流获取令牌时遇到了一些问题 我可以通过以下配置在高级REST客户端实现请求: 为了表示此请求,我实现了以下代码: Rest网关模板: public final class RestGatewayClient { private final List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInter

我是Spotify Web API的新手,在通过客户端凭据流获取令牌时遇到了一些问题

我可以通过以下配置在高级REST客户端实现请求:

为了表示此请求,我实现了以下代码:

Rest网关模板:

public final class RestGatewayClient {

    private final List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();

    public void addHeader(String key, String value) {
        interceptors.add(new HeaderRequestInterceptor(key, value));
    }

    public static RestTemplate getOAuthTemplate() {
        List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
        interceptors.add(new HeaderRequestInterceptor(Constants.SPOTIFY_HEADER_AUTH_KEY, Constants.SPOTIFY_HEADER_AUTH_VALUE));
        interceptors.add(new HeaderRequestInterceptor("Content-Type", "application/x-www-form-urlencoded"));

        RestTemplate template = new RestTemplate();
        template.setInterceptors(interceptors);

        return template;
    }

}
调用API的控制器:

@ResponseBody
    @RequestMapping(value = "/addTrackIntoPlaylist", method = RequestMethod.GET)
    public SpotifyOAuthTokenResource getAlbumTracks() {

        RestTemplate authTemplate = RestGatewayClient.getOAuthTemplate();
        String uri = Constants.SPOTIFY_API_AUTH__URI;

        MultiValueMap<String, String> payload = new LinkedMultiValueMap<String, String>();
        payload.add(Constants.SPOTIFY_PAYLOAD_GRANT_AUTH_KEY, Constants.SPOTIFY_PAYLOAD_GRANT_AUTH_VALUE);
        payload.add(Constants.SPOTIFY_PAYLOAD_SCOPE_AUTH_KEY, Constants.SPOTIFY_PAYLOAD_SCOPE_AUTH_VALUE);

        ResponseEntity<SpotifyOAuthTokenResource> response = authTemplate.postForEntity(uri, payload, SpotifyOAuthTokenResource.class);

        return response.getBody();
    }
但当我在浏览器中调用该方法时,会出现以下错误:

谁能帮我找出我做错了什么


多谢各位

您应该将异常stacktrace粘贴为文本,而不是图像。您应该将异常stacktrace粘贴为文本,而不是图像。
@ResponseBody
    @RequestMapping(value = "/addTrackIntoPlaylist", method = RequestMethod.GET)
    public SpotifyOAuthTokenResource getAlbumTracks() {

        RestTemplate authTemplate = RestGatewayClient.getOAuthTemplate();
        String uri = Constants.SPOTIFY_API_AUTH__URI;

        MultiValueMap<String, String> payload = new LinkedMultiValueMap<String, String>();
        payload.add(Constants.SPOTIFY_PAYLOAD_GRANT_AUTH_KEY, Constants.SPOTIFY_PAYLOAD_GRANT_AUTH_VALUE);
        payload.add(Constants.SPOTIFY_PAYLOAD_SCOPE_AUTH_KEY, Constants.SPOTIFY_PAYLOAD_SCOPE_AUTH_VALUE);

        ResponseEntity<SpotifyOAuthTokenResource> response = authTemplate.postForEntity(uri, payload, SpotifyOAuthTokenResource.class);

        return response.getBody();
    }
@JsonIgnoreProperties(ignoreUnknown = true)
public class SpotifyOAuthTokenResource implements Serializable {

    private static final long serialVersionUID = 1L;

    private String access_token;
    private String token_type;
    private Integer expires_in;
}