스포티 파이 API이 컬 요청은 완벽하게 잘 작동는
curl -X "POST" -H "Authorization: Basic <my-key-here>" -d grant_type=client_credentials https://accounts.spotify.com/api/token
내가 노드에서이 작업을 수행하기 위해 노력하고있어,하지만 작동하지 않는 나쁜 400을 반환 의뢰. 여기 내 코드가있다. 내가 도대체 뭘 잘못하고있는 겁니까?
function AuthRequest(key) {
const req_body_params = JSON.stringify({
grant_type: "client_credentials"
})
const base64_enc = new Buffer(key).toString("base64")
const options = {
host: "accounts.spotify.com",
port: 443,
path: "api/token",
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Basic ${base64_enc}`
}
}
const req = https.request(options, function (res) {
res.on('data', function (data) {
alert("success: " + data)
})
})
req.on('error', function (err) {
alert("error: " + err)
})
req.write(req_body_params)
req.end()
}
여기에 설명 된대로 나는 클라이언트 자격 증명 방법을 사용하려고 해요 : https://developer.spotify.com/web-api/authorization-guide/
무엇이 오류입니까? –
400 잘못된 요청 – user3685285
코드 및 redirect_uri와 같은 필수 매개 변수가 없습니다. – kbariotis