Created
May 6, 2016 21:31
-
-
Save devStepsize/624a5b7371a20aa1f489236a2e99b4bf to your computer and use it in GitHub Desktop.
Get all the albums for a given artist_id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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