zmb3 / spotify

A Go wrapper for the Spotify Web API
Apache License 2.0
1.37k stars 287 forks source link

Add example to get items from next page #75

Closed chrisvdg closed 4 years ago

chrisvdg commented 6 years ago

Currently trying to list the tracks on my playlist but I can't seem to get more than 100 which is the maximum items per page returned by spotify, now how do I fetch the next page of tracks?

I think this could be added to the search example or add a new example that lists all tracks (I can make a pr for that if I can get it working).

My current code

    // list songs from playlist
    songs, err := client.GetPlaylistTracks(user.ID, playlistID)
    if err != nil {
        log.Fatal(err)
    }

    for _, item := range songs.Tracks {
        fmt.Printf("%s: %s (%s)\n", item.Track.ID, item.Track.Name, item.Track.Artists[0].Name)
    }

    fmt.Printf("This playlist has: %d songs (listed %d)\n", songs.Total, len(songs.Tracks))
    // This one outputs: `This playlist has: 144 songs (listed 100)`
chrisvdg commented 5 years ago

Only see something implemented for search results, will try to find some time to come up with something for returned pages of other types and make a pr.

robstarbuck commented 5 years ago

@chrisvdg, any progress with this? It's definitely implementable https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlists-tracks/#paging-object.

chrisvdg commented 5 years ago

@robstarbuck, no, I don't have much spare time and I'm not at all a fast developer. It's already been implemented for SearchResult (https://github.com/zmb3/spotify/blob/035b08df67f491832490996ca695229413877afe/search.go#L163) So I'm going to see if I can just copy that for other types returning pages, or if I can find a neater solution for this.

chrisvdg commented 5 years ago

@robstarbuck, you can follow the progress here: https://github.com/zmb3/spotify/pull/79

zmb3 commented 4 years ago

I added a more convenient way to move through the pages. You can check out the example here: https://github.com/zmb3/spotify/blob/master/examples/paging/page.go