Skip to content

Instantly share code, notes, and snippets.

@devStepsize
Created May 6, 2016 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devStepsize/99d15eadde78fff67b959a2679d51c21 to your computer and use it in GitHub Desktop.
Save devStepsize/99d15eadde78fff67b959a2679d51c21 to your computer and use it in GitHub Desktop.
Get all tracks for a given album_id
import requests
spotify_endpoint = "https://api.spotify.com/v1/"
def get_tracks(album_id):
tracks = []
url = spotify_endpoint + 'albums/%s/tracks' % album_id
while url:
try:
r = requests.get(url).json()
tracks += r.get('items', [])
url = r.get('next')
except requests.exceptions.RequestException as e:
print e
return tracks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment