So I've been trying to fetch my top songs with the code below, but the get request is returning an empty string. What exactly am I doing wrong?
-----------------------------------------
import json
import requests
CLIENT_ID = 'xxxxx'
CLIENT_SECRET = 'xxxxx'
# POST request
auth_response = requests.post(AUTH_URL, {
'grant_type': 'client_credentials',
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
})
# converting the response to JSON
auth_response_data = auth_response.json()
# saving the access token
access_token = auth_response_data['access_token']
headers = {
'Authorization': 'Bearer {token}'.format(token=access_token)
}
# base URL
#GET request
r = requests.get(BASE_URL + 'me/top/tracks', headers = headers, params = {'limit': 50, 'offset': 0, 'time_range': 'medium_term'})
data = r.text
#this print statement below prints out an empty string
print(data)
#the rest of the code is commented out because json.loads() gives an
#error when trying to convert an empty string
# parsed_json = json.loads(data)
# songs = parsed_json['items']
# print(songs)