Skip to content

Unofficial Java-based Wrapper for Spotify Rest API using only Retrofit, GSON, Selenium and WebDriver Manager (to generate access tokens)!

Notifications You must be signed in to change notification settings

cthacker-udel/Java-Spotify-API

Repository files navigation

Public Rest API for Spotify - Cameron Thacker (4/1/2021)

Version dependencies Retrofit Gson Selenium WebdriverManager

GitHub stars

General API Information

All information contained within this repository is referenced from the Spotify Web API Reference website

  • The base http client code is contained within the class called : Spotify Client

  • The Rest API methods that interact with the Retrofit interface are located at the class called : Spotify Rest API

  • The Interfaces corresponding to section in the Web API Reference are located in the Model folder located here : Model

  • Majority of requests are made via Retrofit interface, only 1 request is made via Selenium, and that is generating the access tokens! The tests listed under this folder have been tested for functionality, if any functions do not function properly, please raise an issue! Raise an issue here

All additions and recommendations are welcome!

  • Please check the Project Tab for Updates on current objectives

Usage

  • How to use the Java-Spotify-API wrapper
    • Create an instance of SpotifyClient by calling the constructors listed in this file
    • When you create an instance of SpotifyClient using the constructors listed above, you can utilize the methods listed in SpotifyRestAPI listed in this file

Examples

  • SpotifyClient client = new SpotifyClient();

    • creates an instance of SpotifyClient with empty API key and Secret Key
  • SpotifyClient client = new SpotifyClient("apikey","secretkey");

    • creates an instance of SpotifyClient with API key "apikey" and Secret Key "secretkey" recommended usage
  • SpotifyClient client = new SpotifyClient("apikey","secretkey","accessToken");

    • creates an instance of SpotifyClient with API key "apikey" and Secret Key "secretkey" as well as access token "accessToken"

  • For reference on Implementation of SpotifyClient in coordination with SpotifyRestAPI, check the Test package (specifically the getRequests package)

Step 1 : Create an instance of SpotifyClient, follow the steps under the SpotifyClient Section

Step 2 : Add username or email,password,and this redirect uri: http://localhost:8888/callback/ and add these values by acquiring an instance of the Spotify Login by using the method client.getLogin();, and using the appropriate methods outlined:

  • setEmailOrUsername(String usernameoremail);

    • sets your email or username for acquiring access token
  • setPassword(String password)

    • sets your password for logging into spotify to acquire token
  • setRedirectUri(String redirectUri);

    • sets your redirect uri for acquiring the token

Step 3 : Acquire the access token by calling the method client.requestAuthCodeFlowCode(SpotifyClient client);


Step 1 : Access Album Instance by the method getAlbum() available with your SpotifyClient instance

Step 2 : Access the methods in the album instance, such as addAlbumId, and the setter and getters for individual query options for each request, all parameters are supplied in the tests file, under each type of request.


Step 1 : Access Artist Instance by the method getArtists() available with your SpotifyClient instance

Step 2 : Access the methods in the artist interface, such as addArtistId, and the setter and getters for individual query parameters, all query parameters are supplied in the tests file, under each type of request.


Step 1

  • Access browse seed instance by utilizing the method .getSeed() with your SpotifyClient instance
    • Once the seed instance has been created, add Artist, Track IDs by utilizing the method .addSeedArtist("ID") and .addSeedTrack("ID"), and also adding the genre name (as a String) with the method .addSeedGenre(String genreName)

Step 2

  • Once the seed has been given values for either artist, track, or genre, observe which instances need to be utilized for individual method calls by referencing this file : BrowseTest.java