Skip to content

Instantly share code, notes, and snippets.

@SamuelScheit
Created October 6, 2020 17:43
Show Gist options
  • Save SamuelScheit/7c25bc3670c53e9613a060a83f251754 to your computer and use it in GitHub Desktop.
Save SamuelScheit/7c25bc3670c53e9613a060a83f251754 to your computer and use it in GitHub Desktop.
Query public spotify playlist
const fetch = require("node-fetch");
async function getPlaylist(playlist) {
var accessToken = await fetch(`https://open.spotify.com/playlist/${playlist}`, {
headers: {
"user-agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36",
},
});
accessToken = await accessToken.text();
global.test = accessToken;
accessToken = accessToken.matchAll(/"accessToken":"([\d\w_-]+)"/g).next().value[1];
console.log(accessToken);
var playlist = await fetch(`https://api.spotify.com/v1/playlists/${playlist}?type=track%2Cepisode&market=DE`, {
headers: {
"app-platform": "WebPlayer",
authorization: "Bearer " + accessToken,
"spotify-app-version": "1.1.44.408.gf400d279",
},
});
return playlist.json();
}
// example
getPlaylist("2UJxckjXStA5BA8HEycpBb").then(console.log).catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment