spotify/web-api

Why can't I view more than 50 tracks in the Tracks API?

Closed this issue · 2 comments

Using the web-api, I cannot get more than 50 tracks when getting the user's saved tracks. The documentation makes it clear that the limit is 50, so I was wondering if there is any alternative way to access this information?

0xNF commented

Use the offset field to start past 50.

If you don't specify an offset, it defaults to zero, so repeated calls will always return the same first 50.
The request format you're looking for is https://api.spotify.com/v1/me/tracks?offset=X where X is the next batch of songs you want. For example, https://api.spotify.com/v1/me/tracks?offset=50, followed by https://api.spotify.com/v1/me/tracks?offset=100, etc

edit:

Sorry for snooping, but I found this function in your monthly_music's server script that seems to be the likely culprit:

Your app.get('/view_songs') function sets up the following object:

  var authOptions = {
        url: 'https://api.spotify.com/v1/me/tracks?market=US&offset=50&limit=50',
        headers: {
            'Authorization': "Bearer " + access_token,
            'Content-Type': "application/json",
            'Accept': "application/json"
        }
};

Like discussed above, your url string doesn't take into account that offset needs to be a variable instead of a constant. At the moment it is hard coded to 50, instead of adjusted when needed.

bih commented

To echo what @0xNF said, you'll need to specify the offset parameter as mentioned. This should be your issue, and as a result I'll mark this as closed given it is a question and not a bug report.

Feel free to open a new ticket if you're having issues (or have any other questions)! 👍