Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.

Build Status Release

Spotify Web API for Android

This project is a wrapper for the Spotify Web API. It uses Retrofit to create Java interfaces from API endpoints.

Integrating into your project

This library is available in repository. To use it make sure that repository's url is added to the build.gradle file in your app:

repositories {
    maven { url "" }

dependencies {
    compile 'com.github.kaaes:spotify-web-api-android:0.4.1'

    // Other dependencies your app might use


This project is built using Gradle:

  1. Clone the repository: git clone
  2. Build: ./gradlew assemble
  3. Grab the aar that can be found in spotify-api/build/outputs/aar/spotify-web-api-android-0.4.1.aar


Out of the box it uses OkHttp HTTP client and a single thread executor.

SpotifyApi api = new SpotifyApi();

// Most (but not all) of the Spotify Web API endpoints require authorisation.
// If you know you'll only use the ones that don't require authorisation you can skip this step

SpotifyService spotify = api.getService();

spotify.getAlbum("2dIGnmEIy1WZIcZCFSj6i8", new Callback<Album>() {
    public void success(Album album, Response response) {
        Log.d("Album success",;

    public void failure(RetrofitError error) {
        Log.d("Album failure", error.toString());

It is also possible to construct the adapter with custom parameters.

final String accessToken = "myAccessToken";

RestAdapter restAdapter = new RestAdapter.Builder()
        .setRequestInterceptor(new RequestInterceptor() {
            public void intercept(RequestFacade request) {
                request.addHeader("Authorization", "Bearer " + accessToken);

SpotifyService spotify = restAdapter.create(SpotifyService.class);

Obtaining Access Tokens

The most straightforward way to get the access token is to use the Authentication Library from the Spotify Android SDK. Detailed information how to use it can be found in the Spotify Android SDK Authentication Guide.

Feeling adventurous? You can implement the auth flow yourself, following the Spotify Authorization Guide.

Error Handling

When using Retrofit, errors are returned as RetrofitError objects. These objects, among others, contain HTTP status codes and their descriptions, for example 400 - Bad Request. In many cases this will work well enough but in some cases Spotify Web API returns more detailed information, for example 400 - No search query.

To use the data returned in the response from the Web API SpotifyCallback object should be passed to the request method instead of regular Retrofit's Callback:

spotify.getMySavedTracks(new SpotifyCallback<Pager<SavedTrack>>() {
    public void success(Pager<SavedTrack> savedTrackPager, Response response) {
        // handle successful response

    public void failure(SpotifyError error) {
        // handle error

For synchronous requests RetrofitError can be converted to SpotifyError if needed:

try {
    Pager<SavedTrack> mySavedTracks = spotify.getMySavedTracks();
} catch (RetrofitError error) {
    SpotifyError spotifyError = SpotifyError.fromRetrofitError(error);
    // handle error


Versioning policy

We use Semantic Versioning 2.0.0 as our versioning policy.

Bugs, Feature requests

Found a bug? Something that's missing? Feedback is an important part of improving the project, so please open an issue.


Fork this project and start working on your own feature branch. When you're done, send a Pull Request to have your suggested changes merged into the master branch by the project's collaborators. Read more about the GitHub flow.


A wrapper for Spotify Web API. It uses Retrofit to create Java interfaces from API endpoints







No packages published