首页 > 解决方案 > 在 spotipy 搜索方法中显示带有 preview_url 和曲目名称和图像的歌曲

问题描述

如何显示所有曲目及其 preview_urls 以及图像和曲目名称与 django 应用程序中的 spotipy 中的搜索查询匹配。

我正在尝试在下面执行此操作:

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

现在如何从这个跟踪变量中检索上述信息。

标签: pythondjangospotipy

解决方案


请注意有关如何授权您的 sp 客户端的文档

然后你可以使用搜索方法:

例子

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'])

推荐阅读