Last active
December 8, 2018 20:24
-
-
Save leemartin/7d032685636165d517ec0f21da6163ca to your computer and use it in GitHub Desktop.
Create Spotify Playlist with Artwork
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
// initialize axios instance | |
let spotify = axios.create({ | |
baseURL: 'https://api.spotify.com', | |
headers: { | |
'Authorization': `Bearer ${token}` | |
} | |
}) | |
// get user id for playlist creation | |
spotify.get('/v1/me').then(res => { | |
let userId = res.data.id | |
// create playlist | |
spotify.post(`/v1/users/${res.data.id}/playlists`, { | |
name: "Chris Cornell at City Park on Oct 28, 2011" | |
}).then(res => { | |
let playlistId = res.data.id | |
// add tracks to playlist | |
spotify.post(`/v1/playlists/${playlistId}/tracks?uris=${ids}`).then(res => { | |
// add artwork to playlist | |
spotify.put(`/v1/playlists/${playlistId}/images`, canvas.toDataURL('image/jpeg').replace('data:image/jpeg;base64,', ''), { | |
headers: { | |
'Content-Type': 'image/jpeg' | |
}, | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment