【发布时间】:2018-09-22 21:07:57
【问题描述】:
我正在尝试使用 Node.js 应用程序访问 Spotify Web API。我已将grant_type 指定为authorization_code,但收到unsupported_grant_type 错误,描述为grant_type must be client_credentials, authorization_code or refresh_token。
据我所知,我的 post 请求格式正确且值均正确。不知道还要检查什么。
app.post('/auth', (req, res)=>{
const auth = Buffer
.from(`${process.env.CLIENT_ID}:${process.env.CLIENT_SECRET}`)
.toString('base64');
axios.post(token_uri, {}, {
params: {
'grant_type': 'authorization_code',
'code': req.body.code,
'redirect_uri': redirect_uri,
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET
}, headers: {
'Authorization': `Basic ${auth}`,
'Content-Type':'application/x-www-form-urlencoded'
}
})
.then(res=>{
console.log(res.data)
})
.catch(err=>{
console.log(err)
})
})
【问题讨论】:
标签: node.js authentication spotify