在Soundcloud的API上播放播放列表时,播放列表实际上并未更新?

时间:2015-06-14 05:40:00

标签: soundcloud

当我尝试使用数据结构{"tracks": [{"id": 12345}, {"id": 45678}]}通过API对HTTPPUT播放SoundCloud播放列表时,播放列表不会更新。 API会根据播放列表中的内容返回200响应,完全忽略修改。

我认为可能是错的

  1. SoundCloud API不接受该数据格式

  2. 授权无效,即使它返回200

  3. 代码:

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

1 个答案:

答案 0 :(得分:2)

事实证明我只是发送了错误的数据结构。应该是{'playlist': {'tracks': [{'id': 1234}, {'id': 4567}]}}

https://stackoverflow.com/a/28847716/2350164