我正在嘗試使用Spotipy library for python來拉取某個播放列表中的所有曲目。Spotipy:如何從播放列表中讀取超過100首曲目
無論參數限制如何,user_playlist_tracks函數都限制爲100個軌道。該Spotipy文檔描述爲:
user_playlist_tracks(user, playlist_id=None, fields=None, limit=100, offset=0, market=None)
Get full details of the tracks of a playlist owned by a user.
Parameters:
- user
- the id of the user playlist_id
- the id of the playlist fields
- which fields to return limit
- the maximum number of tracks to return offset
- the index of the first track to return market
- an ISO 3166-1 alpha-2 country code.
與Spotify的認證後,我目前使用的是這樣的:
username = xxxx
playlist = #fromspotipy
sp_playlist = sp.user_playlist_tracks(username, playlist_id=playlist)
tracks = sp_playlist['items']
print tracks
有沒有辦法返回超過100首曲目?我試着在函數參數中設置limit = None,但是它返回一個錯誤。
任何超過100導致此錯誤:'spotipy.client.SpotifyException:HTTP狀態:400,代碼:-1 - https://api.spotify.com/v1/users/im.nick.hello/playlists/7lArr0TzHvKoEsj6cotHqZ/tracks?limit=200&offset=0: 無效的限制# – npbecker
@NickBecker查看此鏈接spotify web API。 https://developer.spotify.com/web-api/get-playlist/ 您需要在分頁對象中使用'offset'鍵。在上面的文章中,您可以看到代碼允許使用'offset'參數。您必須多次調用API,調整每次調用的偏移量。 – rvisio