2

I try to get a playlist from the Spotify API that contains more than 100 tracks. Since there is a rate limit of 100, I try to change the offset parameter each request to get the next 100 tracks. I tried the python library spotipy and tekore, but when I change the offset parameter, I still get the first 100 tracks of the playlist. It doesn't seem to work. I followed this post, as well as this. I also tried to add the query to the url, but I still get the first 100 tracks. What am I missing out?

#using tekore
app_token = tk.request_client_token(client_id, client_secret)
tekore = tk.Spotify(app_token)
playlist = tekore.playlist_items(playlist_id=playlist_id, fields=["tracks.items.track.name"], offset=300)

# using spotipy
spotipy = sp.Spotify(client_credentials_manager=SpotifyClientCredentials(client_id, client_secret))
response = spotipy.playlist_tracks(playlist_id, fields=["tracks.items.track.name"], offset=400)

#using url
r = requests.get(BASE_URL + 'playlists/' + playlist_id + "?offset=100", headers=headers)
Maed
  • 21
  • 2
  • I'm having the same issue, having read the same other posts... I'm using the AutoHotkey Spotify.ahk class but the issue is identical. Adding "?offset=100" to the URL has no effect. The API always returns the first 100 tracks. I know parameters added to the URL are correctly sent to the API. For example, adding "?limit=200" returns the expected error as this exceed the max items number set by the API. But why is the "offset=100" parameter is ignored? – JnLlnd Aug 19 '22 at 03:04

1 Answers1

0

Looking at the JSON returned by the API, I found that the endpoint to get the playlist BASE_URL + 'playlists/' + playlist_id returns info about the playlist and includes the 100 first tracks in the tracks.items array. This endpoint does not support the offset parameter.

To get the remaining tracks, I used the BASE_URL + 'playlists/' + playlist_id + '/tracks?offset=100'. This endpoint supports the limit and offset parameters. It returns the tracks in the items array. All you have to do is loop this API call incrementing offset by 100 until the JSON return an empty items array.

JnLlnd
  • 165
  • 1
  • 14
  • I did not use Python to do it. I used the AutoHotkey class [Spotify.ahk](https://github.com/CloakerSmoker/Spotify.ahk) that I modified to support tracks paging. I could post the modified AHK code if someone needs it. – JnLlnd Aug 20 '22 at 11:40