spotipy: 'Search' funtion does not retrieve all playlists

Describe the bug When ‘Search’ function is used to query playlists matching certan key words, the results do not contain playlists, which are available on official web page of spotify. The search query is the same. While in results of Official Webpage of Spotify I can see playlists, created by Spotify (where owner of playlist is user with id=spotify), in results of Spotipy Library with the same search query, I sometimes get playlists created by Spotify user, sometimes I do not get any.

Your code

playlists = []
for offset in range(0, 1000, 50):
  playlists = playlists + spotify.search(q="Folk punk", limit=50, offset=offset, type='playlist').get('playlists')['items']

Expected behavior I expect to retrieve from Spotipy the same results that I can get from Spotify Web Page.

Output (https://open.spotify.com/search/Folk punk/playlists) - here is the output that I expect to see.

Environment:

  • OS: Windows
  • Python version 3.7.0
  • spotipy version 2.19.0
  • Google Colab

Additional context Additionally, I checked function from Spotipy - user_playlists. While on https://open.spotify.com/user/spotify page I can see that Spotify user has 1520 public playlists, with almost the same code:

spotify_playlists = []
for offset in range(0, 2000, 10):
  spotify_playlists = spotify_playlists + spotify.user_playlists(user = 'spotify', limit=10, offset=offset)['items']
print(len(spotify_playlists))

I am getting less number of playlists (1177) Is there something that I missed?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 28 (13 by maintainers)

Most upvoted comments

Okay. @stephanebruckert Thank you very very much for your help. The solution for this Issue is to use SpotifyOAuth instead of SpotifyClientCredentials.

It’s the same AFAIK

I could make it work, but in this case, I had to go to specific url and then copy the redirected url into input box

Go to the following URL: https://accounts.spotify.com/authorize?client_id=947fdb7706664305a5bb23c0105a9de7&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A4444%2F&scope=+playlist-read-collaborative+playlist-read-private
Enter the URL you were redirected to: http://localhost:4444/?code=AQDlqR6zrg_fKwx1A4Zwt-9l6rLvcR0eSgKDAQRlay6CEXG_4jVKabZW9gIznehq7Ckb4hNC70vUe4jim8EpPG7lBI2bR5M2It9EIZApV7YNHHw120deN7Jb0mbO5anJ6_sh8OTQs3cx25F-YO93DT5z9lPDhgi6kP2sKQ-5AhB4WS-bjM8bfSWwDlnUVjQsuP_strl72UglI5n3IuIEsLSqSXAOQylTzn3vnxz5

And it worked. Is there any way, to not be in a need to do like this?

Ok I found the problem. After I switch from SpotifyOAuth to SpotifyClientCredentials, I didn’t delete the cached token (.cache) on my local environment. So it was still using SpotifyOAuth.

Now I’m cleaning up the token after each run and I can confirm it works with SpotifyOAuth and not with SpotifyClientCredentials!

@stephanebruckert At least, I am not alone with this issue, I appreciate your help)