Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Uvacoder/240c9b05e1416c4a4f431819cd1e4b1e to your computer and use it in GitHub Desktop.

Select an option

Save Uvacoder/240c9b05e1416c4a4f431819cd1e4b1e to your computer and use it in GitHub Desktop.
funny embedding for personal websites
/*
* Spotify Currently Playing
* 28/03/2023
**/
const clientId = "CLIENT_ID",
clientSecret = "CLIENT_SECRET",
refresh_token = "REFRESH_TOKEN",
TOKEN_ENDPOINT = "https://accounts.spotify.com/api/token";
const getBearer = await fetch(TOKEN_ENDPOINT, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: "Basic " + btoa(`${clientId}:${clientSecret}`)
},
body: new URLSearchParams({
grant_type: "refresh_token",
refresh_token: refresh_token
}).toString()
});
let bearer = await getBearer.json();
const getCurrentlyPlaying = await fetch("https://api.spotify.com/v1/me/player/currently-playing", {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Bearer ${bearer}`
}
});
const response = await getCurrentlyPlaying.json();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment