Skip to content

Gruncan/spotify4Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spotify for Java (Still under development)

Spotify api wrapper for java. JavaDocs

Written for enjoyment and a way to learn java concepts that I have rarely/never used. Demonstrated usage of OAuth 2.0 and java reflections, generics, networking, and concurrency.

Latest: v1.5.0

Maven

<dependency>
    <groupId>dev.gruncan.s4j</groupId>
    <artifactId>S4J</artifactId>
    <version>1.5.0</version>
</dependency>

Version Roadmap

  • v1.0.0: WebAPI
  • v2.0.0: AdAPI
  • v3.0.0: Embeds
  • v4.0.0: Open Access

Most often all rquests will be implemented before x.5.0 and all serialization before next major version

How it do

Firstly create an app at spotify's dashboard https://developer.spotify.com/dashboard/applications

Example:

SpotifyClient spotifyClient = new SpotifyClientBuilder("CLIENT_ID", "CLIENT_SECRET", "REDIRECT_URL")
                                                        .getBuiltClient();
  • CLIENT_ID is found at your newly create app's dashboard
  • CLIENT_SECRET is again found at your app's dashboard
  • REDRIECT_URL has to be set in your app's dashboard

getBuiltClient() will make/create the necessary requests/server following spotify's OAuth 2.0 authentication framework

If however you already have an access_token you can use:

SpotifyClient spotifyClient = SpotifyClient.buildFromToken("access_token");

Executing Requests

Executing a request is as simple as instantiating your chosen request class with selected constructor parameters for said request and executing it with your spotifyClient executeRequest

Example:

public static void main(String[] args){
    SpotifyClient spotifyClient = new SpotifyClientBuilder("CLIENT_ID", "CLIENT_SECRET", "REDIRECT_URL").getBuiltClient();
    TrackGet trackGet = new TrackGet("Track_id");
    SpotifyResponse response = spotifyClient.executeRequest(trackGet);
    JSONObject jsonObject = response.getJsonObject();
    System.out.println(jsonObject.toString());
}

Returns a SpotifyResponse that encapsulates the json response from the spotify api

All Json classes were taken from https://github.com/tdunning/open-json with only minor edits.

Requests modelled by this api so far

Album:

Artists:

Audiobooks:

Categories:

Chapters:

Episodes:

Genres:

Markets:

Me:
Playlists:

Search:

Shows:

Tracks:

User:

Scored through requests are implemented but API endpoints do not work on spotify's end.

Future Plans

  • Bring back Spring support for handling user authentication
  • Add more branches of api requests not just web api
  • Optimise multiple call different threads