Dz4j
An unofficial Java wrapper for the Deezer API
Install / Use
/learn @yvasyliev/Dz4jREADME
Deezer API Java Library
A Java implementation of Deezer API.
Third-party dependencies
SLF4JGsonOkHttp
Requirements
- Java 8+
- Maven (or other build tool)
Quickstart
- Add to your
pom.xml:<dependency> <groupId>com.github.yvasyliev</groupId> <artifactId>deezer-api</artifactId> <version>2.1.2</version> </dependency> - Use
DeezerApiinstance 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.<br/>
To obtain access_token our application must be registered and the user must be authorized.<br/>
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.<br/>
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);
}
}
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
