I am trying to do a simple example based on the code for the nodejs 'spotify-web-api-node': https://github.com/thelinmichael/spotify-web-api-node , Im trying to get the example working without having to prompt a user to sign in.
I have setup a spotify developer app so I can get a clientId and clientSecret, and I added the url for my local hosting:
My function gets called when a button is pressed, and tries to authenticate the account and then search for elvis's albums. I added the same url I put in the settings above as a 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);
}
);
});
But when the function gets called; I get a 401 err:
name: "WebapiError", message: "Unauthorized", statusCode: 401}
did I authenticate my account wrong?