检索Spotify播放列表关注者的总数

时间:2017-04-04 22:23:03

标签: python api spotify spotipy

实施例。 www.spotontrack.com/playlists

API documentation中,有一个带有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检索所有信息)..但在完整的结果集中,没有返回跟随者总数(仅总轨迹数)。 / p>

感谢任何建议/协助。

编辑:遇到与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()同样的错误也无效。

0 个答案:

没有答案