Last active
May 26, 2021 14:35
-
-
Save vlad-ds/62aa74732d935a9b68fa002345595818 to your computer and use it in GitHub Desktop.
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 | |
def get_id(track_name: str, token: str) -> str: | |
headers = { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json', | |
'Authorization': f'Bearer ' + token, | |
} | |
params = [ | |
('q', track_name), | |
('type', 'track'), | |
] | |
try: | |
response = requests.get('https://api.spotify.com/v1/search', | |
headers = headers, params = params, timeout = 5) | |
json = response.json() | |
first_result = json['tracks']['items'][0] | |
track_id = first_result['id'] | |
return track_id | |
except: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the "headers" variable was misaligned and causing an unindent problem