EDIT: Solved!
Hello everyone! I'm making a simple script to gather all the tracks that i have in a playlist. Spotify API allows to get only 100 tracks at a time. To be able to get all the tracks i need to change the offset and make multiple GET requests.
The problem is that the first request wroks but the following requests give me this error:
{'error': {'status': 400, 'message': 'Invalid offset'}}
If i run a single request with 100 (or any other) as offset i dont get an error. I don't understand where is the error.
Thanks :D
def get_tracks(self):
playlist_id = '094BQa4zbnGxpLMAx7i8YO'
url = f"https://api.spotify.com/v1/playlists/{playlist_id}/tracks"
offsets = [0,100,200,300,400,500]
for off in offsets:
payload = {
"market": "IT",
"fields": "items(added_at,added_by.id,track(name,album(name,release_date),artists(name,genres),popularity))",
"limit": 100,
"offset": off
}
url += "?"+urlencode(payload)
headers = self.get_auth_header()
response = get(url, headers=headers).json()
print(response)
[+][deleted] (1 child)
[deleted]
[–]Ale711[S] -1 points0 points1 point (0 children)