我正在使用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”是正确的吗? –