我正在使用react-native(並通過使用內置的fetch方法進行本質化操作。我有以下代碼可以發佈到spotify,並且應該返回一個令牌令牌的我收到一個錯誤react-native從spotify API獲取訪問/刷新令牌
代碼:
var btoa = require('base-64');
var authOptions = {
method : 'POST',
body: JSON.stringify({
code: resCode,
redirect_uri: 'myapp://foo',
grant_type: 'authorization_code'
}),
headers: {
'Authorization': 'Basic ' + btoa.encode(secrets.id + ':' + secrets.secret)
},
json: true
};
fetch('https://accounts.spotify.com/api/token', authOptions).then(
(res) => console.log(res)
);
錯誤我收到:
Response {_bodyInit: "{"error":"unsupported_grant_type","error_descripti…redentials, authorization_code or refresh_token"}", _bodyText: "{"error":"unsupported_grant_type","error_descripti…redentials, authorization_code or refresh_token"}", type: "default", url: "https://accounts.spotify.com/api/token", status: 400…}
您確定您發佈的代碼爲「resCode」是正確的嗎? –