【发布时间】:2020-09-06 23:58:11
【问题描述】:
我正在尝试基于 nodejs 'spotify-web-api-node' 的代码做一个简单的示例: https://github.com/thelinmichael/spotify-web-api-node,我试图让示例正常工作,而无需提示用户登录。
我已经设置了一个 spotify 开发者应用,所以我可以获得一个 clientId 和 clientSecret,我添加了我的本地主机的 url:
我的函数在按下按钮时被调用,并尝试验证帐户,然后搜索 elvis 的相册。我在上面的设置中添加了相同的url作为redirectUri:
//popularify spotify api route
app.post('/popularifyRequest', async function (req, res) {
console.log("/popularifyRequest req.body=",req.body)
var SpotifyWebApi = require('spotify-web-api-node');
// credentials are optional
var spotifyApi = new SpotifyWebApi({
clientId: 'f8```````````````````',
clientSecret: 'b7``````````````````````',
redirectUri: 'http://localhost:8080/popularify'
});
// Get Elvis' albums
spotifyApi.getArtistAlbums('43ZHCT0cAZBISjO8DG9PnE').then(
function(data) {
res.send(data.body);
},
function(err) {
res.send(err);
}
);
});
但是当函数被调用时;我收到 401 错误:
name: "WebapiError", message: "Unauthorized", statusCode: 401}
我的帐户验证有误吗?
【问题讨论】: