import requests
def get_top_songs():
# Enter your Spotify API token here
token = "YOUR_SPOTIFY_API_TOKEN"
# Spotify endpoint for top tracks (global)
endpoint = "https://api.spotify.com/v1/me/top/tracks?time_range=medium_term&limit=10"
headers = {
"Authorization": f"Bearer {token}"
}
response = requests.get(endpoint, headers=headers)
if response.status_code == 200:
data = response.json()
top_songs = [track["name"] for track in data["items"]]
return top_songs
else:
print("Failed to fetch data")
return None
top_10_songs = get_top_songs()
if top_10_songs:
print("Top 10 Songs:")
for index, song in enumerate(top_10_songs, start=1):
print(f"{index}. {song}")
0 Comments