thelinmichael / spotify-web-api-node

A Node.js wrapper for Spotify's Web API.
http://thelinmichael.github.io/spotify-web-api-node/
MIT License
3.1k stars 497 forks source link

spotifyApi.getMySavedTracks always fails #255

Open blastbeng opened 5 years ago

blastbeng commented 5 years ago

Hello, i've been using this api with playlists methods for a while, but now i want to get info about all my saved tracks on spotify

But i have an error when i try to:

spotifyApi.getMySavedTracks({ limit : 2, offset: 1 }) .then(function(data) { console.log('Done!'); }, function(err) { console.log('Something went wrong!', err); });

the error is this one:

Something went wrong! { [WebapiError: Forbidden] name: 'WebapiError', message: 'Forbidden', statusCode: 403 }

But i am doing it correctly, this is my code:

var clientId = 'XXXXXXXXXXXXXXXXX'; var clientSecret = 'XXXXXXXXXXXXXXXXXX'; var spotifyApi = new SpotifyWebApi({ clientId: clientId,
clientSecret: clientSecret
}); // Retrieve an access token. spotifyApi.clientCredentialsGrant().then(
function(data) { //console.log('The access token expires in ' + data.body['expires_in']); //console.log('The access token is ' + data.body['access_token']); // Save the access token so that it's used in future calls console.log(new Date()+" "+"setting access token"); spotifyApi.setAccessToken(data.body['access_token']); //processSavedSongs(spotifyApi); //console.log(new Date()+" "+"retrieving user playlists"); spotifyApi.getMySavedTracks({ limit : 2, offset: 1 }) .then(function(data) { console.log('Done!'); }, function(err) { console.log('Something went wrong!', err); });
},
function(err) { console.log('something went wrong when retrieving an access token', err); }
);

leecaleb commented 5 years ago

For Client Credentials Flow, you can't access user's private data which is what getMySavedTracks does.

As documented,

Note: However that this flow does not include authorization and therefore cannot be used to access or to manage a user private data

I tried to use it with my app which authorized user using the Authorization Code Flow. It works when I included user-library-read in the scope!