Reputation: 21
having an issue with adding tracks to a playlist . i can obtain the currently playing song and create a playlist if it doesnt already exist but once i try to add tracks to the playlist it gives me this error
An error occurred: http status: 403, code:-1 You cannot add tracks to a playlist you don't own., reason: None
def add_artist_songs_to_playlist():
sp_oauth = SpotifyOAuth(client_id, client_secret, redirect_uri,
scope="app-remote-control user-library-read user-read-playback-state user-read-private user-read-email playlist-read-private playlist-modify-public playlist-modify-private",
cache_path=".cache-" + username)
spotify_api = spotipy.Spotify(auth_manager=sp_oauth)
artist_name, artist_id = get_artist_info()
try:
songs = []
offset = 0
while True:
result = spotify_api.artist_albums(artist_id, offset=offset)
albums = result['items']
if not albums:
break
for album in albums:
album_tracks = spotify_api.album_tracks(album['id'])
for track in album_tracks['items']:
songs.append(track['id'])
offset += 20
spotify_api.playlist_add_items(playlist_id, songs)
print(f"Successfully added {len(songs)} songs to the playlist!")
except spotipy.client.SpotifyException as e:
print(f"An error occurred: {e}")
Upvotes: 0
Views: 142
Reputation: 1755
How do you get playlist_id
? It is likely not allowing you modify a playlist that does not belong to the authenticated user.
You can try getting the current user's playlists and see if the playlist_id
you are trying to modify is listed in there: https://spotipy.readthedocs.io/en/2.22.1/#spotipy.client.Spotify.current_user_playlists
Upvotes: 1