Last active
October 5, 2021 15:02
-
-
Save maciejkorsan/4669f4d75a1a00f51f5a1be32b96c21a to your computer and use it in GitHub Desktop.
Spotify cover endpoint
This file contains hidden or 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
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