====== Spotify ====== [[https://developer.spotify.com/documentation/web-api/|Web API]]\\ [[https://developer.spotify.com/console/|Console]]\\ [[https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow|Authorization Guide]]\\ ===== Register an App ===== [[https://developer.spotify.com/documentation/general/guides/authorization/app-settings/|Register App]] ===== Get your Secrets ===== Get your ClientID, ClientSecret and CallbackURL from the registered App Create an Authcode, replace and 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=&response_type=code&redirect_uri=http%3A%2F%2F%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 ":" | base64 Example: echo "blabla:thisissecret" | base64 TH1S1SS0D3C0D3DTH1S1SS0D3C0D3DTH1S1SS0D3C0D3DTH1S1SS0D3C0D3D Now get your AccessToken and RefreshToken via CLI curl -H "Authorization: Basic " -d grant_type="authorization_code" -d code="" -d redirect_uri="http%3A%2F%2F%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"} ===== Renew your AccessToken ===== If your AccessToken is expired, renew it with your RefreshToken curl -H "Authorization: Basic " -d grant_type="refresh_token" -d refresh_token="" -d redirect_uri="http%3A%2F%2F%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"} ===== Get your current music ===== 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 " 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"