Napster API身份验证-错误的请求/未经授权

时间:2020-08-22 15:05:56

标签: reactjs api

我正在使用Reactjs进行编码,并尝试 Auth / Outh 进入 Napster Web API ,请遵循此页面上的信息:https://developer.napster.com/api/v2.2#authentication

我当前代码的示例:

const API_KEY = 'OWIxMjhlY2MtOTA3Yi00NWJiLThiYTktODc3OTNiYTQ4MGU4';
const API_KEY_SECRET = 'OWIxMjhlY2MtOTA3Yi00NWJiLThiYTktODc3OTNiYTQ4MGU4';
url: 'https://api.napster.com/oauth/access_token',
method: 'post',
params: {
    client_id: API_KEY,
    client_secret: API_KEY_SECRET
},
headers: {
    'Accept':'application/json',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Authorization': 'Bearer ' + (new Buffer(API_KEY + ':' + API_KEY_SECRET).toString('base64'))
},
data: querystring.stringify({ grant_type: 'authorization_code' })

响应有效载荷:

{"code":"UnauthorizedError","message":"Authentication code not valid"}
{"code":"BadRequestError","message":"Invalid grant_type parameter"}

1 个答案:

答案 0 :(得分:1)

根据下面的文档和示例。...

curl -v -X POST -d "client_id={api_key}&client_secret={api_secret}&response_type=code&grant_type=authorization_code&redirect_uri={redirect_uri}&code={temporary_code}" "https://api.napster.com/oauth/access_token"

...您无需发送授权标头。这是带有所有参数的普通表格。因此,如果您将其余的参数与client_id一起使用:API_KEY ...,它应该可以解决问题。