1

Ex. www.spotontrack.com/playlists

In the API documentation, there is a followers object with a total key, yet this code:

client_credentials_manager = SpotifyClientCredentials()
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

name = "rock"

results = sp.search(q='playlist:' + name,limit=10, type='playlist')

for playlist in results['playlists']['items']:
    print playlist['name'] + ' - ' + playlist['owner']['href'] + ' - ' + playlist['followers']['total']

(which works fine when playlist['followers']['total'] is commented out), returns this:

Traceback (most recent call last):
  File "spotify.py", line 18, in <module>
    print playlist['name'] + ' - ' + playlist['owner']['href'] + ' - ' + playlist['followers']['total']
KeyError: 'followers'

Where am I going wrong? Given the example I linked, it's apparently possible (the SpotOnTrack site footer says all information is retrieved through the API).. yet in the full results set, there is no follower total count (only total tracks) returned.

Any advice / assistance is appreciated.

EDIT: Running into the same problem with PHP (using spotify-php-web-api)

$results = $api->search('rock','playlist');

foreach ($results->playlists->items as $playlist) {
    echo $playlist->name .' - '. $playlist->owner->external_urls->spotify ." - ". $playlist->followers->total ."<br />";
}

Throws:

Notice: Undefined property: stdClass::$followers in /Applications/XAMPP/xamppfiles/htdocs/spotify-web-api-php-master/test.php on line 26

Notice: Trying to get property of non-object in /Applications/XAMPP/xamppfiles/htdocs/spotify-web-api-php-master/test.php on line 26

This also fails using $api->getCategoryPlaylists() with the same error.

Chris Tanner
  • 90
  • 1
  • 6
  • You need to convince your search function to return the full instead of the simplified playlist object. The simplified one doesn't have the followers attribute. – Joooeey Apr 04 '17 at 23:28
  • 1
    Your `playlist` appears to be a simplified playlist object. `playlist['href']` should point you to an endpoint that returns a full playlist object. That full playlist object has the `followers` attribute. – Joooeey Apr 04 '17 at 23:39
  • Thanks, this is what I was surmising. Do you know if this is possible with Spotipy? I'm not locked into doing this with Python, if there are other solutions available I'm open to them. – Chris Tanner Apr 05 '17 at 02:04
  • I don't have spotipy. I's probably possible. What does `print playlist['href']` yield? A URL? A python object? Something else? – Joooeey Apr 05 '17 at 18:07

0 Answers0