[GH-ISSUE #409] Is there a way to get a list of all the playlists a user is following? #242

Closed
opened 2026-02-27 23:21:35 +03:00 by kerem · 9 comments
Owner

Originally created by @Peter-Schorn on GitHub (Jan 5, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/409

I see in the documentation that user_playlist_is_following can be used to check if a user is following a given playlist, but this isn't what I'm looking for. How do I retrieve a list of all the playlists that a user is following? Did I miss this in the docs or does this feature not exist?

Originally created by @Peter-Schorn on GitHub (Jan 5, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/409 I see in the documentation that `user_playlist_is_following` can be used to check if a user is following a given playlist, but this isn't what I'm looking for. How do I retrieve a list of all the playlists that a user is following? Did I miss this in the docs or does this feature not exist?
kerem closed this issue 2026-02-27 23:21:35 +03:00
Author
Owner

@Peter-Schorn commented on GitHub (Jan 6, 2020):

I should also add that neither user_playlists nor current_user_playlists returns playlists that the user is following; they only return playlists that the user created.

<!-- gh-comment-id:571154525 --> @Peter-Schorn commented on GitHub (Jan 6, 2020): I should also add that neither `user_playlists` nor `current_user_playlists` returns playlists that the user is following; they only return playlists that the user created.
Author
Owner

@ritiek commented on GitHub (Jan 6, 2020):

You can fetch all playlists for a user and then check what all playlists are actually owned by that user. If a playlist isn't owned by that user that means the user is probably following this playlist:

# Displays all public playlists that the user follows
user = "ritiek"
playlists = spotify.user_playlists(user)

for playlist in playlists["items"]:
    if not playlist["owner"]["id"] == user:
        print(playlist["name"])

EDIT: When someone follows some playlist, the playlist isn't made public by default. So, you'll need to request access to get user's private following playlists.

<!-- gh-comment-id:571168772 --> @ritiek commented on GitHub (Jan 6, 2020): You can fetch all playlists for a user and then check what all playlists are actually owned by that user. If a playlist isn't owned by that user that means the user is probably following this playlist: ```python # Displays all public playlists that the user follows user = "ritiek" playlists = spotify.user_playlists(user) for playlist in playlists["items"]: if not playlist["owner"]["id"] == user: print(playlist["name"]) ``` **EDIT:** When someone follows some playlist, the playlist isn't made public by default. So, you'll need to request access to get user's private following playlists.
Author
Owner

@Peter-Schorn commented on GitHub (Jan 6, 2020):

I've tried using user_playlists(user) and current_user_playlists. Both of these functions only returned playlists that I created. Also, I only have a total of 20 playlists, including both created and followed playlists, so it's not like the results are being paginated . Here's the relevant section of my code (you can find the full script here if you're interested). Maybe you can figure out why I'm only getting the playlists I created. Some of the playlists I'm following are created by Spotify, which I assume aren't private, and I'm not even getting those playlists. Also, I'm now aware that you can use while tracks['next']: for paginated results, but I haven't got around to changing that part yet.

username = 'myUsername'

client_id = os.environ.get('CLIENT_ID')
client_secret = os.environ.get('CLIENT_SECRET')
redirect_uri = 'http://localhost/'
scope = 'user-library-read'


token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri)

if token:
    sp = spotipy.Spotify(auth=token)

    playlists = sp.user_playlists(username)

    # I've also tried this:
    # playlists = sp.current_user_playlists()

    for playlist in playlists['items']:
        plistURI  = playlist['uri']
        tTracks   = playlist['tracks']['total']
        if tTracks == 0: continue

        for offset in range(0, 10000, 100):
            tracks = sp.user_playlist_tracks(username, plistURI, limit=100, offset=offset)
            if len(tracks['items']) == 0: break
         
            # Do a bunch of things for all of the tracks
            download_tracks(tracks)
<!-- gh-comment-id:571178335 --> @Peter-Schorn commented on GitHub (Jan 6, 2020): I've tried using `user_playlists(user)` and `current_user_playlists`. Both of these functions only returned playlists that I created. Also, I only have a total of 20 playlists, including both created and followed playlists, so it's not like the results are being paginated . Here's the relevant section of my code (you can find the full script [here](https://github.com/Peter-Schorn/Play-Spotify-Songs-from-Spotlight-Search) if you're interested). Maybe you can figure out why I'm only getting the playlists I created. Some of the playlists I'm following are created by Spotify, which I assume aren't private, and I'm not even getting those playlists. Also, I'm now aware that you can use `while tracks['next']:` for paginated results, but I haven't got around to changing that part yet. ``` username = 'myUsername' client_id = os.environ.get('CLIENT_ID') client_secret = os.environ.get('CLIENT_SECRET') redirect_uri = 'http://localhost/' scope = 'user-library-read' token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri) if token: sp = spotipy.Spotify(auth=token) playlists = sp.user_playlists(username) # I've also tried this: # playlists = sp.current_user_playlists() for playlist in playlists['items']: plistURI = playlist['uri'] tTracks = playlist['tracks']['total'] if tTracks == 0: continue for offset in range(0, 10000, 100): tracks = sp.user_playlist_tracks(username, plistURI, limit=100, offset=offset) if len(tracks['items']) == 0: break # Do a bunch of things for all of the tracks download_tracks(tracks)
Author
Owner

@Peter-Schorn commented on GitHub (Jan 6, 2020):

Could it be something to do with the scope I'm using?

<!-- gh-comment-id:571189385 --> @Peter-Schorn commented on GitHub (Jan 6, 2020): Could it be something to do with the scope I'm using?
Author
Owner

@ritiek commented on GitHub (Jan 6, 2020):

Could it be something to do with the scope I'm using?

That's what it seems like! Try using playlist-read-private as the scope.

<!-- gh-comment-id:571191993 --> @ritiek commented on GitHub (Jan 6, 2020): > Could it be something to do with the scope I'm using? That's what it seems like! Try using `playlist-read-private` as the scope.
Author
Owner

@Peter-Schorn commented on GitHub (Jan 6, 2020):

Could you do me a favor and give me a list of all the different scopes that can be used? I didn't find that on the docs.

<!-- gh-comment-id:571197190 --> @Peter-Schorn commented on GitHub (Jan 6, 2020): Could you do me a favor and give me a list of all the different scopes that can be used? I didn't find that on the docs.
Author
Owner

@ritiek commented on GitHub (Jan 6, 2020):

Does it work for you with changing the scope as I mentioned in previous comment? The scope list can found at https://beta.developer.spotify.com/documentation/general/guides/scopes/.

<!-- gh-comment-id:571200308 --> @ritiek commented on GitHub (Jan 6, 2020): Does it work for you with changing the scope as I mentioned in previous comment? The scope list can found at https://beta.developer.spotify.com/documentation/general/guides/scopes/.
Author
Owner

@Peter-Schorn commented on GitHub (Jan 6, 2020):

When I used playlist-read-private it retrieved ALL of my playlists! Thanks!

<!-- gh-comment-id:571200395 --> @Peter-Schorn commented on GitHub (Jan 6, 2020): When I used `playlist-read-private` it retrieved *ALL* of my playlists! Thanks!
Author
Owner

@stephanebruckert commented on GitHub (Jan 12, 2020):

Looks answered by @ritiek, thanks & closing!

<!-- gh-comment-id:573369107 --> @stephanebruckert commented on GitHub (Jan 12, 2020): Looks answered by @ritiek, thanks & closing!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#242
No description provided.