Get your ClientID, ClientSecret and CallbackURL from the registered App
Create an Authcode, replace <YOURCLIENTID> and <YOURCALLBACKURL> with yours, you also might need to change the scope if you want to gather more info than just your current music. After opening the URL in your browser you will be redirected to an URL with your Code.
https://accounts.spotify.com/authorize?client_id=<YOURCLIENTID>&response_type=code&redirect_uri=http%3A%2F%2F<YOURCALLBACKURL>%2Fcallback%2F&scope=user-read-currently-playing Example: https://accounts.spotify.com/authorize?client_id=123abcidontcare&response_type=code&redirect_uri=http%3A%2F%2Flocalhost:3000%2Fcallback%2F&scope=user-read-currently-playing http://localhost:3000/callback/?code=AQCPtOSCKsPt..........YIcyfimgKFeejPg
Now decode your ClientID and ClientSecret with Base64 (online or via CLI)
echo "<YOURCLIENTID>:<YOURCLIENTSECRET>" | base64 Example: echo "blabla:thisissecret" | base64 TH1S1SS0D3C0D3DTH1S1SS0D3C0D3DTH1S1SS0D3C0D3DTH1S1SS0D3C0D3D
Now get your AccessToken and RefreshToken via CLI
curl -H "Authorization: Basic <YOURBASE64CODE>" -d grant_type="authorization_code" -d code="<YOURAUTHCODE>" -d redirect_uri="http%3A%2F%2F<YOURCALLBACKURL>%2Fcallback%2F" https://accounts.spotify.com/api/token Example: curl -H "Authorization: Basic TH1S1SS0D3C0D3DTH1S1SS0D3C0D3DTH1S1SS0D3C0D3DTH1S1SS0D3C0D3D" -d grant_type="authorization_code" -d code="AQCPtOSCKsPt..........YIcyfimgKFeejPg" -d redirect_uri="http%3A%2F%2Flocalhost:3000%2Fcallback%2F" https://accounts.spotify.com/api/token {"access_token":"BQCMW.........z8gNg","token_type":"Bearer","expires_in":3600,"refresh_token":"AQDn.........cXK_gU","scope":"user-read-currently-playing"}
If your AccessToken is expired, renew it with your RefreshToken
curl -H "Authorization: Basic <YOURBASE64CODE>" -d grant_type="refresh_token" -d refresh_token="<YOURREFRESHTOKEN>" -d redirect_uri="http%3A%2F%2F<YOURCALLBACKURL>%2Fcallback%2F" https://accounts.spotify.com/api/token Example: curl -H "Authorization: Basic TH1S1SS0D3C0D3DTH1S1SS0D3C0D3DTH1S1SS0D3C0D3DTH1S1SS0D3C0D3D" -d grant_type="refresh_token" -d refresh_token="AQDn.........cXK_gU" -d redirect_uri="http%3A%2F%2Flocalhost:3000%2Fcallback%2F" https://accounts.spotify.com/api/token {"access_token":"BQC2e.........LDSA","token_type":"Bearer","expires_in":3600,"scope":"user-read-currently-playing"}
You can get your music via the following CURL to check your AccessToken
curl -X "GET" "https://api.spotify.com/v1/me/player/currently-playing" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer <YOURACCESSTOKEN>" Example: curl -X "GET" "https://api.spotify.com/v1/me/player/currently-playing" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer BQCMW.........z8gNg"