播放列表创建请求停止出错,我不知道原因。当我试图诊断这个问题时,我必须改变任何错误。我以为它试图创建一个同名的播放列表,但spotify允许重复播放列表。可能我使用的令牌或令牌对象有问题。对不起的。
但是,在清除前一个问题时,我还发现了另一个问题:添加到曲目时,指定的是曲目uri(spotify:track:abcdef123),而不仅仅是曲目id(abcdef123)。我修改了spotify的以下播放列表:
def spotify_write_playlist(auth, name, tracks, public=True):
ids = []
for track in tracks:
track_id = track.services['spotify']
if track_id: ids.append("spotify:track:"+track_id)
headers = {
"authorization":"Bearer " + auth.token,
"content-type":"application/json"
}
data = {
"name":name,
"public":public
}
r = makeRequest("https://api.spotify.com/v1/users/" + auth.username + "/playlists", "post", 201, json=data, headers=headers)
playlist_id = json.loads(r.content)['id']
data = {"uris":ids}
r = makeRequest("https://api.spotify.com/v1/users/" + auth.username + "/playlists/" + playlist_id + "/tracks", "post", 201, json=data, headers=headers)
return playlist_id