Display song with preview_url and track name and image in spotipy search method

491 views Asked by At

How to display all the track with their preview_urls and image and track name matching with the search query made in spotipy in django application.

I am trying to do this below :

sp = client_credentials_manager=SpotifyClientCredentials()
track = sp.search("My Heart Will Go On", limit=10, offset=0, type='track', market=None)

Now how to retrive above mentioned information from this track variable.

1

There are 1 answers

0
ujlbu4 On BEST ANSWER

Take a notice on documentation how to authorize your sp client

And then you can use search method:

example

client_id = 'your-client-id'
client_secret = 'your-client-secret'

auth_manager = SpotifyClientCredentials(client_id, client_secret)
sp = spotipy.Spotify(auth_manager=auth_manager)
track = sp.search("My Heart Will Go On", limit=10, offset=0, type='track', market=None)

tracks = track['tracks']
for item in tracks['items']:
    print(item['preview_url'])