Spotify
Intro
The Spotify API is used to track your music listening history and track library.
Data points
The following data points are available for this integration:
Data point | Description |
---|---|
history | Listening history |
library | Library |
top-tracks | Top tracks |
top-artists | Top artists |
If you want to enable all data points, you can simply use all
instead:
Authentication
You need to register an application on Spotify for Developers and will receieve a client ID and client secret. Use these credentials to generate an access/refresh token pair, which is used to authenticate with the Spotify API.
The scopes required when generating credentials are:
user-top-read
(top artists and content)user-library-read
("Your Music" library)
To generate tokens when you don't have a OAuth flow set up, add the default URL http://localhost:3000/callback under "Redirect URIs" in your Spotify app, and run the callbackUrl
function:
Running the above will log the URL to visit in your web browser, for example:
This URL will redirect you to a URL starting with http://localhost:3000/callback, which looks like this:
In this above URL, the query parameter after ?code=
and before &state=
is your code
. You can exchange this for the required tokens, like so:
This will log your access token and refresh token to the console. Copy and paste these and set them as the environment variables described above.
Environment variables
When the tokens are generated, you can set the following environment variables:
Environment variable | Description |
---|---|
SPOTIFY_CLIENT_ID | Client ID |
SPOTIFY_CLIENT_SECRET | Client secret |
SPOTIFY_ACCESS_TOKEN | Access token |
SPOTIFY_REFRESH_TOKEN | Refresh token |