Java wrapper for the Spotify web API
Simple to use Java wrapper for the Spotify web API
IMPORTANT: The library is still under development, you can check out what needs to be completed in the checklist below. Only some of the endpoints and authentication flow has been
completed.
Some of Spotify’s Web API is available to users even without an access token or performing any form of user authentication,
the library supports the access of these resources.
In order to begin using the Spotify API, you have to create what is known as a SpotifyUser. This can be done either
by following a flow and generating one, or
manually creating one yourself:
SpotifyUser oneTimeUser = new SpotifyUser("<access_token>");
SpotifyUser refreshUser = new SpotifyUser("<access_token>", "refresh_token");
After that, you can proceed to apply the methods you wish to use on this SpotifyUser object.
Example: Getting an album
Album album = oneTimeUser.getAlbum("0sNOF9WDwhWunNAHPD3Baj").build().execute();
System.out.println(album.getArtist());
Example: Generating recommendations based off a seed
Recommendation recommendation = oneTimeUser
.getSeedRecommendation()
.limit(5)
.addSeedGenre("party")
.setSeedArtists(listOf("4NHQUGzhtTLFvgF5SZesLK", "43ZHCT0cAZBISjO8DG9PnE"))
.danceability(SeedQuery.Flag.Min, 0.6)
.build()
.execute();
recommendation.getSeeds().forEach(System.out::println);
More information:
The Spotify Web API offers 3 methods of user authentication.
The library offers means to authenticate users in all 3 ways.
This form of authorization is used when you need to have a persistent session for the user and want the user to be
able to continually access the API without having to authorize themselves everytime their access token expires.
Example implementation of the authorization flow using the library
More information about the process steps
This method of user authentication is recommended if the information you want to retrieve from the user’s account is
one-time and you won’t need a persistent connection.
Example implementation of the implicit grant flow using the library
More information about the process steps
This method of user authentication is used for server-to-server communication and does not require any authorization.
However, because of that, there is no refresh token provided.
Example implementation of the client credential flow using the library
More information about the process steps
The project’s code of conduct can be found here.
If you wish to make a contribution, be sure to read the contribution guide.
java-spotify-wrapper is licensed under the MIT license, more about that can be found here.