Spotify 애플리케이션을 개발 중이며 토큰을 받고 싶습니다. 내가 Client Credentials Flow을 다음과 curl
모든 것을 사용하고클라이언트 자격 증명 흐름이 컬링에서는 작동하지만 브라우저에서는 작동하지 않습니다.
잘 작동 :
var url = "https://accounts.spotify.com/api/token";
var authentication = "YjU4Y...llYTQ=";
var params = { grant_type: "client_credentials" };
var auth = "Basic " + authentication;
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
headers: {
'Authorization' : auth,
'Access-Control-Allow-Origin': '*'
},
data: params,
success: function(data) {
console.log('success', data);
}
});
:
$ curl -H "Authorization: Basic YjU4Y...llYTQ=" \
-d grant_type=client_credentials \
https://accounts.spotify.com/api/token
# Response:
# {
# "access_token":"BQD3u...W4iJA",
# "token_type":"Bearer",
# "expires_in":3600
# }
그리고 여기, 내가 같은 결과를 얻을려고 내 HTML 파일의 자바 스크립트 코드가있다 그러나 다음 오류가 발생합니다.
XMLHttpRequest cannot load https://accounts.spotify.com/api/token . Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
내가 틀렸어?
Javascript를 사용하여 정적 HTML 파일에서 Spotify API를 사용하는 방법은 정말 있습니까?
http://stackoverflow.com/questions/33188989/allowing-cors-jquery-post-requests-to-spotify-api-on-express-js-server/33198424#33198424 관련성이있는 것 같습니다. 그리고 https://github.com/spotify/web-api-auth-examples. Spotify의 http://stackoverflow.com/users/540274/jos%C3%A9-m-p%C3%A9rez는 SO 답장 질문에 관한 것 같습니다. – sideshowbarker
@sideshowbarker에게 감사하지만 어떤 서버 측 코드도 원하지 않습니다. –
클라이언트 측에서 인증을 시도하는 경우 왜 암시 적 승인 대신 CORS로 인해 서버 측 응용 프로그램이 필요한 클라이언트 자격 증명을 사용하고 있습니까? 어쩌면 내가 그 질문을 잘못 이해 했는지도 모른다. –