Last active
June 16, 2024 22:41
-
-
Save rohitjethoe/3fd0d358ed1d1e767ddb02771d533dc5 to your computer and use it in GitHub Desktop.
funny embedding for personal websites
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
| /* | |
| * 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