当我尝试使用数据结构{"tracks": [{"id": 12345}, {"id": 45678}]}
通过API对HTTPPUT播放SoundCloud播放列表时,播放列表不会更新。 API会根据播放列表中的内容返回200响应,完全忽略修改。
SoundCloud API不接受该数据格式
授权无效,即使它返回200
import requests
playlist_url = 'https://api.soundcloud.com/playlists/XXXXX?client_id=XXXXX'
like_url = 'https://api.soundcloud.com/users/XXXXX/favorites?client_id=XXXXX'
likes = requests.get(like_url)
likes_json = likes.json()
# oauth2_token = requests.post('https://api.soundcloud.com/oauth2/token', data=opts).json()
oauth2_token = 'XXXXX'
playlist = {'tracks': []}
for like in likes_json[::-1]:
track_id = like['id']
playlist['tracks'].append({'id': track_id})
resp = requests.put('https://api.soundcloud.com/playlists/XXXXX', json=playlist, params={
'oauth_token': oauth2_token,
'client_id': 'XXXXX',
'client_secret': 'XXXXX'
})
答案 0 :(得分:2)
事实证明我只是发送了错误的数据结构。应该是{'playlist': {'tracks': [{'id': 1234}, {'id': 4567}]}}
。