Skip to content

yvasyliev/deezer-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central javadoc MIT License Build status CodeQL Technical Debt Quality Gate Status Reliability Rating Duplicated Lines (%) Vulnerabilities Bugs Security Rating Maintainability Rating Code Smells Lines of Code PRs Welcome

Deezer API Java Library

A Java implementation of Deezer API.

Third-party dependencies

  • SLF4J
  • Gson
  • OkHttp

Requirements

  1. Java 8+
  2. Maven (or other build tool)

Quickstart

  1. Add to your pom.xml:
    <dependency>
        <groupId>com.github.yvasyliev</groupId>
        <artifactId>deezer-api</artifactId>
        <version>2.1.0</version>
    </dependency>
  2. Use DeezerApi instance to execute Deezer API requests:
    public class DeezerApp {
        public static void main(String[] args) throws DeezerException {
            DeezerApi deezerApi = new DeezerApi();
    
            Album album = deezerApi.album().getById(302127).execute();
            System.out.println(album);
    
            TrackData trackData = deezerApi.search().searchTrack("eminem").execute();
            System.out.println(trackData);
        }
    }

OAuth

Some Deezer API requests should be executed with access_token param passed.
To obtain access_token our application must be registered and the user must be authorized.
To register new app:

  1. Go to https://developers.deezer.com/myapps
  2. Create new Application.

Now we are ready to authorize the user. Deezer uses OAuth 2.0 protocol for authentication and authorization.

Authorization flow example

public class DeezerApp {
    /**
     * Can be found at https://developers.deezer.com/myapps
     */
    private static final int APP_ID = 123;

    /**
     * Can be found at https://developers.deezer.com/myapps
     */
    private static final String SECRET = "secret_string";

    /**
     * Your domain where user will be redirected to.
     */
    private static final String REDIRECT_URI = "your.domain.com";

    public static void main(String[] args) throws DeezerException {
        DeezerApi deezerApi = new DeezerApi();

        // Step 1. Create login URL.
        String loginUrl = deezerApi.auth().getLoginUrl(APP_ID, REDIRECT_URI, Permission.BASIC_ACCESS);
        System.out.println(loginUrl); // https://connect.deezer.com/oauth/auth.php?app_id=123&redirect_uri=your.domain.com&perms=basic_access

        /*
         * Step 2. Authorize.
         *
         *      1. Open loginUrl in your browser.
         *      2. Login to Deezer. (if haven't done yet)
         *      3. Accept application permissions.
         *      4. Find a 'code' parameter in URL after redirection to:
         *          http://redirect_uri?code=A_CODE_GENERATED_BY_DEEZER
         */
        System.out.print("Please enter code: ");
        String code = new Scanner(System.in).next();

        // Step 3. Get access_token.
        DeezerAccessToken accessToken = deezerApi.auth().getAccessToken(APP_ID, SECRET, code).execute();
        deezerApi.setAccessToken(accessToken);

        // Now we are ready to execute any request we want.
        User me = deezerApi.user().getMe().execute();
        System.out.println(me);

        TrackData favouriteTracks = deezerApi.user().getFavouriteTracks(me.getId()).execute();
        System.out.println(favouriteTracks);
    }
}

Features

  1. Interceptors
  2. Artist#picture, Genre#picture
  3. Artist#trackList
  4. Page#next, Page#prev

To improve

  1. Migrate User#status to enum.
  2. Infos is not fully populated.
  3. Migrate Offer#tryAndBuy to enum or boolean.
  4. SearchHistory#result - it's unclear what structure result may have.
  5. Does search / history return prev/next links? If so, need to add deserializer.