Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fetch tracks from getMyPlaylists? #177

Open
priyanallan opened this issue May 10, 2019 · 3 comments
Open

How to fetch tracks from getMyPlaylists? #177

priyanallan opened this issue May 10, 2019 · 3 comments

Comments

@priyanallan
Copy link

Hi,

I need to fetch playlists and corresponding tracks of a user. I use getMyPlaylists and it returns PlaylistSimple which has tracks of type 'PlaylistTracksInformation' but there is no information of Track (album, artist etc.) like in 'TrackSimple'. How do I fetch tracks of user playlists using 'PlaylistTracksInformation' ?

Thanks in advance.

@willccoates
Copy link

Since you are trying to obtain the playlists and the playlists tracks, you would first want to use getMyPlaylists to obtain a list of your playlists via PlaylistSimple, since PlaylistSimple gives you access to the playlists ID. I personally used the methods that included the callback in the parameters because when i tried using the methods that returned a specific type, it would give me permission errors but the callbacks allowed for a successful access of whatever i was trying to access.

Next you need to call getPlaylistTracks (shown below in the screen capture) using the required information ( user ID, playlist ID, options, callback) to access the information about the playlist tracks.

image

One thing to note about getPlaylistTracks is that it can only retrieve 100 tracks at a time. check out this link for more information about the options parameter #105 (comment).

I hope this helps!

@priyanallan
Copy link
Author

Thanks for the response. As per the docs the number of playlists returned for a user is 'Default:20; minimum: 1 and maximum: 1=50) what is the difference between default and maximum?
Screenshot 2019-05-16 at 16 22 00

@willccoates
Copy link

Essentially, when calling getMyPlaylist() you have the options parameter, where it is a Map<String, object>. When you create this Map object you specify what the maximum amount of items you want to receive and if you do not specify, it will default to 20. So following the example by Kaaes at this link: #105 (comment) we can see you create the Map object and set the size, in the case for playlists 50 by doing

options.put(SpotifyService.LIMIT, 50);

Then, you tell Spotify where you want to begin in the list, in this case the beginning being 0

options.put(SpotifyService.OFFSET, 0);

If you have more than 50 playlists, you would need to adjust the OFFSET to the next set of 50 playlists by changing the 0 to 50,100,150, etc.

As you can see in the documentation, the query parameters are optional, so by just simply creating the options Map object and not putting anything inside, the Spotify API defaults to 20 playlists.

I hope this helps! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants