-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathspotifyexample
More file actions
33 lines (25 loc) · 960 Bytes
/
spotifyexample
File metadata and controls
33 lines (25 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#Use the spotify API to grab album data from an artist
#Imports the json library
import json
#imports the requests library
import requests
#States where the base URL is. You can find this in the API documentation
api_url_base = 'https://api.spotify.com/'
#If you need to register for an API toen you can include that here, otherwise delete this line
api_token='Instert Token here'
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer {0}'.format(api_token)}
def get_albums():
api_url = '{0}v1/artists/6vWDO969PvNqNYHIOW5v0m/albums'.format(api_url_base)
response = requests.get(api_url, headers=headers)
if response.status_code == 200:
return json.loads(response.content.decode('utf-8'))
else:
return None
album_info = get_albums()
if album_info is not None:
print("Here's your info: ")
for album in album_info.items():
print(album)
else:
print('[!] Request Failed')