Skip to content

Instantly share code, notes, and snippets.

@gate5th
Created September 12, 2018 18:47
Show Gist options
  • Save gate5th/c27c7cb64fa1dd1107b4bb73d10f807a to your computer and use it in GitHub Desktop.
Save gate5th/c27c7cb64fa1dd1107b4bb73d10f807a to your computer and use it in GitHub Desktop.
oldschoolshuffle
export async function getUserPlaylists() {
//returns an array of objects with playlist name (like "Favorite Smashing Pumpkins jamz")
//and the id of the playlist. Use this to feed the playlists selection list
try {
const playlistsResponse = await spotifyApi.getUserPlaylists();
//playlistsResponse.items are the actual playlist objects
const playlists = playlistsResponse.items.map((playlistObject) => {
const {id, name} = playlistObject;
return {id: id, playlistName: name}
})
return playlists
}
catch(err) {
//return default array with note that can't download playlists
console.error('Error: Attempting to get user playlists', err);
console.error(err.stack);
return [{id: null, playlistName: "Can't Download your Playlists!"}]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment