我决定尝试使用SpotipyAPI只是玩玩。我已经设置了client_id和client_secret环境变量,但是当我运行代码时出现了上面的错误。所以我决定用一段示例代码来看看它是否能运行。
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
lz_uri = 'spotify:artist:36QJpDe2go2KgaRleHCDTp'
spotify = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())
results = spotify.artist_top_tracks(lz_uri)
for track in results['tracks'][:10]:
print('track : ' + track['name'])
print('audio : ' + track['preview_url'])
print('cover art: ' + track['album']['images'][0]['url'])
print()
是否有一些我需要添加到我的代码或我做其他错误的东西?
提前感谢,
弗雷德
您首先必须访问:https://developer.spotify.com/dashboard/applications。创建一个客户端id和secret。然后参考https://developer.spotify.com/documentation/general/guides/authorization-guide/身份验证。