Added scope, 'playlist-read-private', to examples that access user playlists 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>
This commit is contained in:
slipstream42 2020-10-23 17:57:14 -04:00 committed by GitHub
parent bea781d28f
commit 275cd7ea89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 4 deletions

View File

@ -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

View File

@ -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']):

View File

@ -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'])

View File

@ -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']