A Java implementation of Deezer API.
SLF4J
Gson
OkHttp
- Java 8+
- Maven (or other build tool)
- Add to your
pom.xml
:<dependency> <groupId>com.github.yvasyliev</groupId> <artifactId>deezer-api</artifactId> <version>2.1.0</version> </dependency>
- 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); } }
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:
- Go to https://developers.deezer.com/myapps
- Create new Application.
Now we are ready to authorize the user. Deezer uses OAuth 2.0 protocol for authentication and authorization.
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);
}
}
- Interceptors
Artist#picture
,Genre#picture
Artist#trackList
Page#next
,Page#prev
- Migrate
User#status
to enum. Infos
is not fully populated.- Migrate
Offer#tryAndBuy
toenum
orboolean
. SearchHistory#result
- it's unclear what structureresult
may have.- Does
search / history
returnprev
/next
links? If so, need to add deserializer.