Skip to content

Instantly share code, notes, and snippets.

@maciejkorsan
Last active October 5, 2021 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maciejkorsan/4669f4d75a1a00f51f5a1be32b96c21a to your computer and use it in GitHub Desktop.
Save maciejkorsan/4669f4d75a1a00f51f5a1be32b96c21a to your computer and use it in GitHub Desktop.
Spotify cover endpoint
const authkey = // authkey stored somewhere ie. file / database
const client_id = ""; // Your client id
const client_secret = ""; // Your secret
const refresh_token = "";
console.log(authkey.keyvalue);
const getCover = () => {
axios
.get("https://api.spotify.com/v1/me/player/currently-playing", {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Bearer ${authkey.keyvalue}`
}
})
.then(res => {
if (res.data.is_playing) { response(res.data.item.album.images[1].url) }
else {
response('notplaying.png');
}
})
.catch(res => {
console.log("update klucza")
console.log(res)
axios
.post(
"https://accounts.spotify.com/api/token",
qs.stringify({
grant_type: "refresh_token",
refresh_token: refresh_token
}),
{
headers: {
Authorization:
"Basic " +
Buffer.from(client_id + ":" + client_secret).toString(
"base64"
),
}
}
)
.then(async res => {
console.log(res.data.access_token) // store it somewhere for later use
})
.catch(e => {
console.log(e.response);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment