Use this when the weekly update workflow fails with an error like invalid_grant or Refresh token expired.
The workflow seeds Spotipy's cache from the GitHub secret SPOTIFY_REFRESH_TOKEN and then calls Spotify to refresh the access token.
In this repository that happens in:
/home/runner/work/KEXP/KEXP/.github/workflows/weekly-catalog-update.yml/home/runner/work/KEXP/KEXP/processCatalog.py
If the stored refresh token is expired, revoked, or otherwise invalid, the workflow cannot update the playlist until a new refresh token is generated and stored.
This does not by itself indicate a Spotify-wide API change. It usually means the saved token for this app/user pair is no longer valid.
- Create or confirm your Spotify app in the Spotify developer dashboard.
- Make sure the app's redirect URI exactly matches the URI used by this repo, such as
https://localhost:8080. - In the repository root, create a local config file from the sample:
- Copy
/home/runner/work/KEXP/KEXP/config_sample.jsonto/home/runner/work/KEXP/KEXP/config.json
- Copy
- Edit
/home/runner/work/KEXP/KEXP/config.jsonand fill in:SPOTIPY_CLIENT_IDSPOTIPY_CLIENT_SECRETSPOTIPY_REDIRECT_URIspotify_usernameplaylist_name
- Install the required package locally:
pip install spotipy
- From the repository root, run:
python /home/runner/work/KEXP/KEXP/testSpotipy.py
- Complete the Spotify authorization flow for the scopes:
playlist-modify-publicplaylist-modify-private
- After authorization succeeds, Spotipy will write a cache file named:
/home/runner/work/KEXP/KEXP/.cache-<spotify_username>
- Open that cache file and copy the value of
refresh_token.
- Open the repository settings on GitHub.
- Go to Settings → Environments → weekly update.
- Update the environment secret named
SPOTIFY_REFRESH_TOKENwith the newrefresh_tokenvalue. - Confirm the other Spotify values are still correct:
- secret:
SPOTIPY_CLIENT_ID - secret:
SPOTIPY_CLIENT_SECRET - variable:
SPOTIPY_REDIRECT_URI - variable:
SPOTIFY_USERNAME - variable:
PLAYLIST_NAME
- secret:
- Re-run the Weekly KEXP Catalog Update workflow manually.
- Confirm the
Run KEXP catalog processingstep succeeds. - If it still fails with
invalid_grant, check for one of these mismatches:- wrong Spotify app client ID or secret
- redirect URI in GitHub does not exactly match the Spotify app settings
- token generated for a different Spotify user
- Spotify access for the app was revoked and needs to be re-authorized again
After updating GitHub, remove any local files that contain secrets if you do not need them anymore, especially:
/home/runner/work/KEXP/KEXP/config.json/home/runner/work/KEXP/KEXP/.cache-<spotify_username>