Dynamically generated Spotify widgets for GitHub readme!
Copy-paste this in your GitHub readme, and that's it!
Change <RENDER_INSTANCE_NAME>
with the name of your personal instance.
<img src="https://<RENDER_INSTANCE_NAME>.onrender.com/api/spotify/now" />
You can customize the look of the card using pre-built themes.
Add ?theme=THEME_NAME
like so:
<img src="https://<RENDER_INSTANCE_NAME>.onrender.com/api/spotify/now?theme=vue-dark" />
To make this app work it is necessary to provide data that changes from user to user, thus making it mandatory to create your own instance.
Of course, everything will be completely free, thanks to Render, but it will take a few minutes to set up.
Spotify Setup
- Create a Spotify Application.
- Take note of
Client ID
andClient Secret
. - Click on Edit Settings.
- Add
http://localhost/callback/
on Redirect URIs section.
- Navigate to the following URL:
- Remember to replace
{SPOTIFY_CLIENT_ID}
with theClient ID
of your newly created application.
https://accounts.spotify.com/authorize?client_id={SPOTIFY_CLIENT_ID}&response_type=code&scope=user-read-currently-playing,user-read-recently-played&redirect_uri=http://localhost/callback/
- Remember to replace
- Log in, take note of the
{CODE}
portion fromhttp://localhost/callback/?code={CODE}
. - Combine in a string
{SPOTIFY_CLIENT_ID}:{SPOTIFY_CLIENT_SECRET}
and encode into Base64.- WARNING:
{SPOTIFY_CLIENT_ID}
and{SPOTIFY_CLIENT_SECRET}
are actually separated by:
.
- WARNING:
- Run from Git Bash the following curl command:
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Basic {BASE64}" -d "grant_type=authorization_code&redirect_uri=http://localhost/callback/&code={CODE}" https://accounts.spotify.com/api/token
- Take note of the Refresh Token.
Render Setup
- Sign in to Render or create a new account here.
- Click on New Web Service.
- Connect your GitHub account by clicking "configure account" and installing Render for GitHub. Guide
- Connect your repo.
- Fill the form, remember to specify
npm install
instead ofyarn
as Build Command. - Once the app is deployed, click on the app to go to the dashboard.
- Go to the "Environment" tab and add the following env vars.
SPOTIFY_CLIENT_ID
: Your Spotify Application Client IDSPOTIFY_CLIENT_SECRET
: Your Spotify Application Client SecretSPOTIFY_REFRESH_TOKEN
: Your Spotify Refresh Token.
Made with Javascript, EJS and ❤️