【发布时间】:2016-06-07 07:55:42
【问题描述】:
我正在使用 react-native(并且本质上使用内置的 fetch 方法。我有以下代码发布到 spotify 并且应该返回一个令牌,而不是我收到错误的令牌。
代码:
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正确吗?
标签: ios react-native fetch spotify