2

I'm a very noob user, I'm trying to play some tracks from Spotify in my Android app. Currently I'm using the kaaes API: https://github.com/kaaes/spotify-web-api-android

and I'm struggling to retrieve the tracks from a very specific Playlist and a very specific userId. It seems that I'm not able to do it, the only examples I found are old and don't help me. Here's what I tried:

Accessing list of playlists from Pager object

SpotifyApi api = new SpotifyApi();
SpotifyService spotify = api.getService();

spotify.getPlaylistTracks("USERID","PLAYLISTID", new Callback<Pager<PlaylistTrack>>() {
        @Override
            public void success(Pager<PlaylistTrack> playlistTrackPager, Response response) {
            Log.e("TEST", "GOT the tracks in playlist");
            List<PlaylistTrack> items = playlistTrackPager.items;
            for( PlaylistTrack pt : items){
                Log.e("TEST", pt.track.name + " - " + pt.track.id);
            }
        }
        @Override
            public void failure(RetrofitError error) {
                Log.e("TEST", "Could not get playlist tracks");
            }
    });

It enlights red Callback (when I call new Callback<Pager<PlaylistTrack>>()) and it says:

Cannot resolve symbol 'Callback'

If I alt+enter click on it it says:

Add library 'retrofit-2.4.0.retrofit-2.4.0' to classpath

If I do it, then it underlines all Callback<Pager<PlaylistTrack>>, with error:

then I alt+enter again and it says:

Class 'Anonymous Class derived from Callback' must either be declared abstract or implement abstract method 'onResponse(Call, Response) in 'Callback'

Then I alt+enter click again and I choose: Implements methods onResponse() and onFailure() and I adjust the old code with the new methods so it will be:

spotify.getPlaylistTracks("USERID","PLAYLISTID", new Callback<Pager<PlaylistTrack>>() {
            @Override
            public void onResponse(Call<Pager<PlaylistTrack>> playlistTrackPager, Response<Pager<PlaylistTrack>> response) {
                Log.e("TEST", "GOT the tracks in playlist");
                List<PlaylistTrack> items = playlistTrackPager.items;
                for( PlaylistTrack pt : items){
                    Log.e("TEST", pt.track.name + " - " + pt.track.id);
                }
            }

            @Override
            public void onFailure(Call<Pager<PlaylistTrack>> call, Throwable t) {
                Log.e("TEST", "Could not get playlist tracks");
            }
        });

But now, .items is enlighted red and says:

Cannot resolve symbol 'items'

I couldn't find anything online about this.. it seems that I'm not able to fit the old code examples I found with the new API methods.

Thank you

tomaculum
  • 547
  • 4
  • 15
BROKENCODE
  • 85
  • 1
  • 10

1 Answers1

2

Your first code snipped does not show any errors in my test project. I guess there are issues with overlapping imports or other libraries.

Please check if it works if you add the following imports and remove the other retrofit/ kaaes imports:

import kaaes.spotify.webapi.android.SpotifyApi;
import kaaes.spotify.webapi.android.SpotifyService;
import kaaes.spotify.webapi.android.models.Pager;
import kaaes.spotify.webapi.android.models.PlaylistTrack;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;

If this does not work, please remove the retrofit 2 library from your class path / project and try it again, since this wrapper still uses retrofit 1.9.0.

tomaculum
  • 547
  • 4
  • 15
  • Thank you tomaculum, I miss the Retrofit import, but Android Studio delete it as soon as I cntl+v them.. I followed the instruction on the Retrofit page https://square.github.io/retrofit/ : Downloaded the .jar file -> new -> new module -> import jar aar package - retrofit added in dependencies: implementation 'com.squareup.retrofit2:retrofit:2.4.0' – BROKENCODE Oct 24 '18 at 06:53
  • Then, if I use the question's first code snippet, and I write the Retrofit imports, it doesn't delete them, but they are greyed out (retrofit is highlighted in red) and AS says: Cannot resolve symbol 'retrofit' What can I do? Do I need to download the previous version of Retrofit? Thank you – BROKENCODE Oct 24 '18 at 07:01
  • Do you use retrofit anywhere else in your project? If no, just delete the retrofit2 dependency in your build.gradle file and/ or delete the downloaded jar file and try it again. The required 1.9 retrofit version will be automatically added (somewhere in the background) to your project when you did set up the kaees wrapper dependency. – tomaculum Oct 24 '18 at 10:13