1

前任。www.spotontrack.com/playlists

API 文档中,有一个followers带有total键的对象,但是这段代码:

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

(当playlist['followers']['total']被注释掉时工作正常),返回:

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

我哪里错了?鉴于我链接的示例,这显然是可能的(SpotOnTrack 网站页脚说所有信息都是通过 API 检索的)。但是在完整的结果集中,没有返回的追随者总数(只有总曲目)。

任何建议/帮助表示赞赏。

编辑:遇到与 PHP 相同的问题(使用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 />";
}

抛出:

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

$api->getCategoryPlaylists()这也使用相同的错误失败。

4

0 回答 0