Python 正在检索Spotify播放列表跟随者的总数

Python 正在检索Spotify播放列表跟随者的总数,python,api,spotify,spotipy,Python,Api,Spotify,Spotipy,例如:www.spotontrack.com/playlists 在中,有一个带有total键的followers对象,但此代码: client_credentials_manager = SpotifyClientCredentials() sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) name = "rock" results = sp.search(q='playlist:' +

例如:www.spotontrack.com/playlists

在中,有一个带有
total
键的
followers
对象,但此代码:

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'

使用
$api->getCategoryPlaylists()
也会失败,出现相同的错误。

您需要说服搜索函数返回完整的播放列表对象,而不是简化的播放列表对象。简化的播放列表没有followers属性。您的
播放列表
似乎是一个简化的播放列表对象
playlist['href']
应将您指向返回完整播放列表对象的端点。完整播放列表对象具有
followers
属性。谢谢,这就是我所猜测的。你知道Spotipy是否可以做到这一点吗?我并没有用Python来做这件事,如果有其他的解决方案,我也愿意接受。我没有spotipy。我有可能。
print playlist['href']
能产生什么效果?URL?python对象?还有什么?你需要说服你的搜索功能返回完整的而不是简化的播放列表对象。简化的播放列表没有followers属性。您的
播放列表
似乎是一个简化的播放列表对象
playlist['href']
应将您指向返回完整播放列表对象的端点。完整播放列表对象具有
followers
属性。谢谢,这就是我所猜测的。你知道Spotipy是否可以做到这一点吗?我并没有用Python来做这件事,如果有其他的解决方案,我也愿意接受。我没有spotipy。我有可能。
print playlist['href']
能产生什么效果?URL?python对象?还有别的吗?
$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