我正在使用家庭帐户(高级),此代码返回“需要高级”错误。我的代码如下:
device_id = '0d1841b0976bae2a3a310dd74c0f3df354899bc8'
def playSpotify():
client_credentials_manager = SpotifyClientCredentials(client_id='e8c483b4795248d8a1d2565581773d8a', client_secret='0260ab662191470da382c6a9cb452340')
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
playlists = sp.user_playlists('gh8gflxedxmp4tv2he2gp92ev')
#while playlists:
#for i, playlist in enumerate(playlists['items']):
#print("%4d %s %s" % (i + 1 + playlists['offset'], playlist['uri'], playlist['name']))
#if playlists['next']:
#playlists = sp.next(playlists)
#else:
#playlists = None
#sp.shuffle(true, device_id=device_id)
#sp.repeat(true, device_id=device_id)
sp.start_playback(device_id=device_id, context_uri='spotify:playlist:4ndG2qFEFt1YYcHYt3krjv')
答案 0 :(得分:0)
使用SpotifyClientCredentials
时,生成的令牌不属于任何用户,而是属于应用程序,因此会出现错误消息。
您需要做的是改为使用SpotifyOAuth
。因此,要初始化Spotipy,只需执行以下操作:
sp = spotipy.Spotify(auth_manager=spotipy.SpotifyOAuth())
这将打开浏览器选项卡,并要求您登录帐户。