Based on: https://gist.github.com/marco79cgn/79a6a265d978dc22cc2a12058b24e02b
Widget for iOS 18 showing your most listened to tracks within the past four weeks.
Instructions from Authorization Code Flow
1.) Go to Spotify Developer API and create a new Application
2.) Click "Edit Settings" and add https://spotify.com as Redirect URI
3.) Open a Bash and set Client ID and Client Secret as environment variables
export CLIENT_ID=1234567890 # EDIT && \
export CLIENT_SECRET=mfq837wfgw8wvcg673gnfm # EDIT && \
export REDIRECT_URI=https%3A%2F%2Fspotify.com && \
export BEARER=$(echo -n "${CLIENT_ID}:${CLIENT_SECRET}" | base64)
4.) Open a new incognito browser tab: https://accounts.spotify.com/authorize?client_id=<YOURCLIENTID>&response_type=code&redirect_uri=https%3A%2F%2Fspotify.com&scope=user-top-read (Make sure to replace <YOURCLIENTID> within the URL)
5.) Click "Accept"
6.) You will be redirected to something like https://www.spotify.com/de/?code=AQD4q4v6Klt9ZW5VtTbnbHAWDLKK8y1t6Ammov.....
7.) Store this code once again in an environment variable
export RETURN_CODE=AQD4q4v6Klt9ZW5VtTbnbHAWDLKK8y1t6Ammov.....
8.) Run the below command without any modifications
curl -H "Authorization: Basic ${BEARER}" -d grant_type=authorization_code -d code=${RETURN_CODE} -d redirect_uri=${REDIRECT_URI} https://accounts.spotify.com/api/token > spotify_access_token.json && \
cat spotify_access_token.json
9.) You'll receive an access and a refresh token
10.) Create a new File called spotify-credentials.json using all your collected data:
{
"clientSecret": "YOURCLIENTSECRET",
"clientId": "YOURCLIENTID",
"accessToken": "ACCESS TOKEN FROM STEP 8",
"refreshToken": "REFRESH TOKEN FROM STEP 8"
}
11.) Store this JSON File in your iCloud Drive under Scriptable/spotify-credentials.json
- Make sure to have iOS 18 installed
- Download Scriptable App
- Copy the code from this repo into the clipboard
- Paste it in a new Scriptable script
- Create a new Scriptable widget, choose a layout (last one recommended)
- Under Parameters select how many tracks will be shown (max is 10) and select the period ([1-10],["short", "medium", "long"])