Created
September 12, 2018 18:47
-
-
Save gate5th/c27c7cb64fa1dd1107b4bb73d10f807a to your computer and use it in GitHub Desktop.
oldschoolshuffle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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