Site Tools


linux:ubuntu:spotify

This is an old revision of the document!


Spotify

Register an App

Get your Secrets

Get your ClientID, ClientSecret and CallbackURL from the 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 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"}

Get your current music

You can get your music via the following CURL to check your token

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"

linux/ubuntu/spotify.1640732929.txt.gz · Last modified: 2021/12/29 00:08 by lunetikk