Adding tracks to a playlist in Spotify using Spotipy
<p>I'm using the Python bindings for the Spotify API to list an artists top tracks and add them to a playlist, but it fails every time, as if it excepts a different type of input.</p>
<p>New_Track_List is a string containing the output of the top tracks lookup as either:</p>
<h1>1: URIs:</h1>
<p>Example: &quot;spotify:track:1pAyyxlkPuGnENdj4g7Y4f, spotify:track:7D2xaUXQ4DGY5JJAdM5mGP, spotify:track:74mG2xIxEUJwHckS0Co6jF, spotify:track:2rjqDPbLlbQRlcj8DVM9kn,&quot;</p>
<p>Using URIs I get this back from the function</p>
<pre><code>sp.user_playlist_add_tracks(username, playlist_id=playlist, tracks=New_Track_List)
</code></pre>
<p>Traceback:</p>
<pre><code>spotipy.client.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/users/smokieprofile/playlists/40aijTeKoxo5u1VSS9E3UQ/tracks: You can add a maximum of 100 tracks per request.
</code></pre>
<p>There's only 20 tracks in the string.</p>
<h1>2nd try: Track IDs:</h1>
<p>Example: &quot;1pAyyxlkPuGnENdj4g7Y4f, 7D2xaUXQ4DGY5JJAdM5mGP, 74mG2xIxEUJwHckS0Co6jF, 2rjqDPbLlbQRlcj8DVM9kn&quot;</p>
<p>Same traceback output.</p>
<h1>Using a single track ID</h1>
<pre><code>sp.user_playlist_add_tracks(username, playlist_id=playlist, tracks=&quot;spotify:track:74mG2xIxEUJwHckS0Co6jF&quot;)
</code></pre>
<p>Trying to add just ONE track, gets me this message:</p>
<pre><code>spotipy.client.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/users/smokieprofile/playlists/40aijTeKoxo5u1VSS9E3UQ/tracks: Invalid track uri: spotify:track:s
</code></pre>
<p>Same message using only the Track ID, as if it only checks the first letter of the passed string.</p>
<pre><code>    sp.user_playlist_add_tracks(username, playlist_id=playlist, tracks=&quot;7D2xaUXQ4DGY5JJAdM5mGP&quot;)
</code></pre>
<p>Error traceback:</p>
<pre><code>spotipy.client.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/users/smokieprofile/playlists/40aijTeKoxo5u1VSS9E3UQ/tracks: Invalid track uri: spotify:track:7
</code></pre>