【问题标题】:Retrieving Spotify playlist follower count in Python在 Python 中检索 Spotify 播放列表的关注者数量
【发布时间】:2020-10-07 23:09:49
【问题描述】:

我想使用 Python 检索我的 Spotify 播放列表的关注者数量。我一直在搜索https://developer.spotify.com/documentation/web-api/reference-beta/#category-playlists,但还没有找到方法。但是,我找到了一个关于如何检索播放列表的曲目 ID 的工作代码,我该如何调整它以获取关注者?

def getTrackIDs(user, playlist_id):
    ids = []
    playlist = sp.user_playlist(user, playlist_id)
    for item in playlist['tracks']['items']:
        track = item['track']
        ids.append(track['id'])
    return ids

ids = getTrackIDs('User', 'Playlist_Id')

print(len(ids))
print(ids)

【问题讨论】:

    标签: python spotify playlist spotipy


    【解决方案1】:

    看看应该通过获取播放列表返回的播放列表对象。

    https://developer.spotify.com/documentation/web-api/reference/object-model/#playlist-object-full.

    它有 followers 属性,这是一个位于此处的关注者对象

    https://developer.spotify.com/documentation/web-api/reference/object-model/#followers-object.

    followers 对象包含total 属性,这应该是您要查找的内容。

    虽然我无法运行您的代码,但我想结果应该如下所示。让我知道这是否适合您(我无法运行代码)。

    def getPlaylistFollowerCount(user, playlist_id):
        playlist = sp.user_playlist(user, playlist_id)
        return playlist['followers']['total']
    

    【讨论】:

      猜你喜欢
      • 2016-03-18
      • 1970-01-01
      • 2016-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-02
      • 1970-01-01
      相关资源
      最近更新 更多