0

I'm trying to retrieve the id of my playlists in Spotify so that I can show the content (playlists name, tracks, etc.) in a ListView in my Android app. I can't find a way to get that data.

I copied the Android Quick Start source code given by Spotify. Everything works clean as long as I know the playlist ID ("spotify:playlist:5smL9JMG88uvAabko1c5P0"). But what about if I don't know it and I want to get it from Spotify (so, for example, if I have many playlists in my account I can decide in my app which one to play)? Is there a get method for Android? I don't show any code because it's the same provided by Spotify.

Marco
  • 35
  • 1
  • 7

1 Answers1

0

If you do not know the playlist id of the playlist you can use the following Spotify Web API Endpoint to get all of the users playlists : Get List Users Playlists

There are libraries for the Spotify Web API, therefore you do not need to implement this by yourself if you do not want to.

If you choose the kaaes/spotify-web-api-android library, the code could be something like this:

SpotifyApi api = new SpotifyApi();
api.setAccessToken("yourAccessToken");
SpotifyService spotify = api.getService();

spotify.getMyPlaylists(new SpotifyCallback<Pager<PlaylistSimple>>() {
    @Override
    public void failure(SpotifyError spotifyError) {
        // handle error
    }

    @Override
    public void success(Pager<PlaylistSimple> playlistSimplePager, Response response) {
        // do something
        // for example
        for(PlaylistSimple playlistSimple: playlistSimplePager.items) {
            Log.d("playlist:", playlistSimple.name);
        }
    }
});
tomaculum
  • 547
  • 4
  • 15
  • Thanks! It looks very good. I'm just having hard time to get the access token. As soon as I make it I'll give it a try. – Marco Apr 13 '19 at 05:35
  • To obtain the access token you can use a library, too. [Android SDK Authentication Guide](https://developer.spotify.com/documentation/android/guides/android-authentication/#single-sign-on-with-spotify-client-and-a-webview-fallback) If this doesn't help open another question and provide some details regarding the authentication question/issue. – tomaculum Apr 13 '19 at 09:53
  • I tried everything I could imagine but with no success. So I opened a new question here https://stackoverflow.com/questions/55671086/i-cant-retrieve-an-access-token-from-spotify-for-my-app – Marco Apr 14 '19 at 00:43