This project was developed to integrate and explore the functionalities of the Spotify API, utilizing development best practices within the Java ecosystem.
Before running the application, ensure you have the following installed:
- Java JDK 17 or higher
- Maven 3.8+ (optional, as you can use the included Maven Wrapper)
- A Spotify Developer account to obtain API credentials
- Language: Java 21
- Framework: Spring Boot 4.0.6 (Web, DevTools)
- API: Spotify Web API Java
- Dependency Manager: Maven
- Productivity: Lombok
In order to run the application, please follow the next steps:
Open your terminal or command prompt and execute the following command:
git clone https://github.com/ramosprodev-krs/spotify-api-application.gitAfter cloning, navigate into the project directory:
cd spotify-api-applicationNow, you need to add your Spotify API credentials directly into the configuration file.
- Navigate to: src/main/resources/application.properties
- Fill in the following fields with your credentials:
spotify.client.id=YOUR_CLIENT_ID (replace with your client id)
spotify.client.secret=YOUR_CLIENT_SECRET (replace with your client secret)
spotify.redirect.uri=http://127.0.0.1:8080/spotify/api/callbackOnce the application.properties is updated, compile and run the Spring Boot application using the Maven Wrapper:
On Linux/macOS:
./mvnw spring-boot:run
On Windows: mvnw.cmd spring-boot:run
The server will start at http://localhost:8080.
To interact with the Spotify API, you must first authorize the application to access your data.
-
Start Login: Open your browser and go to: http://localhost:8080/spotify/api/login
-
Spotify Authorization: You will be redirected to the official Spotify login page. Log in (if necessary) and click "Agree" to authorize the application.
-
Callback & Token: After clicking agree, Spotify will redirect you back to: http://127.0.0.1:8080/spotify/api/callback The application will automatically exchange the authorization code for an Access Token.
-
Success: Once you see the message "You are successfully authenticated!", the application is ready to fetch your data.
After authentication, you can access the following data directly in your browser or via tools like Postman or Insomnia:
| Endpoint | Function |
|---|---|
| /spotify/api/current-user | Display the user logged in. |
| /spotify/api/my-saved-albums | List your saved albums in the library. |
| /spotify/api/my-saved-tracks | List your saved tracks in the library. |
| /spotify/api/my-top-tracks | Display your most listened tracks. |
| /spotify/api/my-top-artists | Display your most listened artists. |
- Token Persistence: The Access Token is stored in memory. If you restart the Spring Boot application, you must go through the /login flow again.
- Redirect URI: Ensure that the 'spotify.redirect.uri' in your application.properties exactly matches the one registered in your Spotify Developer Dashboard (e.g., check for 127.0.0.1 vs localhost).
- Data Format: All endpoints (except login/callback) return data in JSON format using optimized DTOs.
If you found this project helpful, please consider giving it a ⭐ to support its development!