To integrate with the Spotify API, follow these steps:
-
Create a Spotify Application: Go to the Spotify Developer Dashboard and create a new application.
-
Note Down Client ID and Client Secret: Upon creating the application, note down the
Client ID
andClient Secret
. -
Edit Application Settings:
- Click on Edit Settings for your newly created application.
- Add
http://localhost/callback/
to the list of Redirect URIs.
-
Authorization URL: Navigate to the following URL in your browser:
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/
-
Authorize and Get Code:
- Log in with your Spotify account.
- Save the
{CODE}
portion from the redirected URL:http://localhost/callback/?code={CODE}
.
-
Generate Base64 String:
- Create a string by combining
{SPOTIFY_CLIENT_ID}:{SPOTIFY_CLIENT_SECRET}
. - Encode this string into Base64.
- Create a string by combining
-
Retrieve Refresh Token:
- Execute 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
- Save the Refresh token obtained from the response.
- Execute the following
With these credentials and tokens, you can now access Spotify's API endpoints securely.