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 499 forks source link

getPlaylist returns invalid playlist ID no matter input #299

Open ZoeyOneOhOne opened 4 years ago

ZoeyOneOhOne commented 4 years ago

get

The first function returns "uncaught exception: Object" but the second one returns: "{\n \"error\" : {\n \"status\" : 404,\n \"message\" : \"Invalid playlist Id\"\n }\n}" regardless of which playlist ID I try to use. Other spotify api calls I have in my app work just fine. Only this call is acting weird.

fabiogaliano commented 4 years ago

It seems to be working over here, used the same playlist as above.

ZoeyOneOhOne commented 4 years ago

That's really interesting... I will try to figure something out when I get off work and I'll let you know. Thank you for getting back to me.

ZoeyOneOhOne commented 4 years ago

Ya I still can't get this particular call to work. Any ideas?

fabiogaliano commented 4 years ago

At first everything seems fine in your code, I'm just not sure how you are calling the function. Either way here's a snippet that works.

var SpotifyWebApi = require("spotify-web-api-node");

let spotifyApi = new SpotifyWebApi();
spotifyApi.setAccessToken(process.env.ACCESS_TOKEN);

async function getSlamsPlaylist(playlistID) {
  let playlistObj = (await spotifyApi.getPlaylist(playlistID)).body;
  //do something with playlistObj
  console.log(playlistObj);
}

getSlamsPlaylist("7CoPUH1fJFKzcc7NAIv9XU");

// without async 

function getSlamsPlaylistV2(playlistID) {
  spotifyApi
    .getPlaylist(playlistID)
    .then(res => console.log(res.body))
    .catch(err => console.log(err));
}

getSlamsPlaylistV2("7CoPUH1fJFKzcc7NAIv9XU");