Skip to content

Instantly share code, notes, and snippets.

@devStepsize
Created May 6, 2016 21:31
Show Gist options
  • Save devStepsize/624a5b7371a20aa1f489236a2e99b4bf to your computer and use it in GitHub Desktop.
Save devStepsize/624a5b7371a20aa1f489236a2e99b4bf to your computer and use it in GitHub Desktop.
Get all the albums for a given artist_id
import requests
spotify_endpoint = "https://api.spotify.com/v1/"
def get_albums(artist_id):
albums = []
params = {'album_type': 'album'}
url = spotify_endpoint + 'artists/%s/albums' % artist_id
while url:
try:
r = requests.get(url, params=params).json()
albums += r.get('items', [])
url = r.get('next')
except requests.exceptions.RequestException as e:
print e
return albums
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment