我在从网络API访问播放列表列表时遇到了一些问题。我真的想使用getMyPlaylists
,但它似乎不是我使用的选项,所以目前我正在尝试这个:
api.setAccessToken(response.getAccessToken());
SpotifyService spotify = api.getService();
final UserPrivate me = spotify.getMe();
Pager<PlaylistSimple> test = spotify.getPlaylists(me.id);
但是,如何从测试对象访问信息?或者更好的是,如何更改此设置以便我可以使用getMyPlaylists
?
由于
答案 0 :(得分:1)
This is how you do it..
SpotifyApi api = new SpotifyApi();
api.setAccessToken(token);
SpotifyService spotify = api.getService();
spotify.getPlaylists("USERID", new Callback<Pager<Playlist>>() {
@Override
public void success(Pager<Playlist> playlistPager, Response response) {
Log.d("TEST", "Got the playlists");
List<Playlist> playlists = playlistPager.items;
for (Playlist p : playlists) {
Log.e("TEST", p.name + " - " + p.id);
}
}
@Override
public void failure(RetrofitError error) {
Log.e("TEST", "Could not get playlists");
}
});
Once you know the playlist ID, you can then fetch the tracks of the playlist with something like this :
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");
}
});
coutesy lunai
https://github.com/spotify/android-sdk/issues/79