Skip to content

Commit

Permalink
Added scope, 'playlist-read-private', to examples that access user pl…
Browse files Browse the repository at this point in the history
…aylists using the spotipy api: current_user_playlists() (fixes #591) (#595)

* - Added scope, 'playlist-read-private', to examples that access user playlists using the spotipy api: current_user_playlists() (fixes #591)

* Fix example to use user_playlists again

Co-authored-by: Stephane Bruckert <stephane.bruckert@gmail.com>
  • Loading branch information
lfg6000 and stephanebruckert committed Oct 23, 2020
1 parent bea781d commit 275cd7e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- playlist_tracks example code no longer prints extra characters on final loop iteration
- SpotifyException now thrown when a request fails & has no response ( fixes #571, #581 )
- Added scope, 'playlist-read-private', to examples that access user playlists using the spotipy api: current_user_playlists() (fixes #591)

### Changed

Expand Down
3 changes: 2 additions & 1 deletion examples/my_playlists.py
Expand Up @@ -3,7 +3,8 @@
import spotipy
from spotipy.oauth2 import SpotifyOAuth

sp = spotipy.Spotify(auth_manager=SpotifyOAuth())
scope = 'playlist-read-private'
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))

results = sp.current_user_playlists(limit=50)
for i, item in enumerate(results['items']):
Expand Down
13 changes: 11 additions & 2 deletions examples/user_playlists.py
@@ -1,10 +1,19 @@
# Shows a user's playlists (need to be authenticated via oauth)

import sys
import spotipy
from spotipy.oauth2 import SpotifyOAuth

if len(sys.argv) > 1:
username = sys.argv[1]
else:
print("Whoops, need a username!")
print("usage: python user_playlists.py [username]")
sys.exit()

sp = spotipy.Spotify(auth_manager=SpotifyOAuth())
playlists = sp.current_user_playlists()

playlists = sp.user_playlists(username)

for playlist in playlists['items']:
print(playlist['name'])
print(playlist['name'])
3 changes: 2 additions & 1 deletion examples/user_playlists_contents.py
Expand Up @@ -13,7 +13,8 @@ def show_tracks(results):


if __name__ == '__main__':
sp = spotipy.Spotify(auth_manager=SpotifyOAuth())
scope = 'playlist-read-private'
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))

playlists = sp.current_user_playlists()
user_id = sp.me()['id']
Expand Down

0 comments on commit 275cd7e

Please sign in to comment.