首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python playlists[items]是空的

python playlists[items]是空的
EN

Stack Overflow用户
提问于 2019-01-18 18:47:45
回答 2查看 680关注 0票数 0

使用下面的代码,我可以为我的用户检索一个playlists对象,但是items条目的列表是空的。我有几百个播放列表,所以我一定是在这段代码中遗漏了什么。

代码语言:javascript
复制
 import spotipy
 import spotipy.util as util

 username='xxxxx'
 clientid='xxxxx'
 clientsecret='xxxxx'
 redirecturi='http://localhost'
 thescope='user-library-read'

 print("Requesting token...")
 token = util.prompt_for_user_token(username,scope=thescope,client_id=clientid,client_secret=clientsecret,redirect_uri=redirecturi)
 print("Token is %s" % token)
 if token:
     sp = spotipy.Spotify(auth=token)
     playlists = sp.user_playlists(username)
     print("Playlists are ", playlists)
 else:
     print "Can't get token for", username

产出如下:

代码语言:javascript
复制
 Requesting token...
 Token is<token>
 ('Playlists are ', {u'items': [], u'next': None, u'href': u'https://api.spotify.com/v1/users/havanon/playlists?offset=0&limit=50', u'limit': 50, u'offset': 0, u'total': 0, u'previous': None})
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-01-24 19:01:36

这似乎很管用。但是它不返回播放列表文件夹。我还没有发现任何关于这类事情的污点。

代码语言:javascript
复制
 #!/usr/bin/env python2
 import sys
 import spotipy
 import spotipy.util as util

 username='xxx'
 clientid='xxx'
 clientsecret='xxx'
 redirecturi='http://localhost'
 thescope='playlist-read-private'

 token = util.prompt_for_user_token(username,scope=thescope,client_id=clientid,client_secret=clientsecret,redirect_uri=redirecturi)
 if token:
     sp = spotipy.Spotify(auth=token)
     playlists = sp.current_user_playlists()
     while playlists:
         for i, playlist in enumerate(playlists['items']):
             print("%4d %s %s" % (i + 1 + playlists['offset'], playlist['uri'],  playlist['name']))
         if playlists['next']:
             print("getting next 50")
             playlists = sp.next(playlists)
         else:
             playlists = None
 else:
     print ("Can't get token for", username)
票数 0
EN

Stack Overflow用户

发布于 2019-01-23 18:33:50

我认为libraryplaylist是可以访问的不同资源。

您可能需要应用playlist-read-private作用域。

playlist-read-private

  • 描述:读取对用户私有播放列表的访问权限。
  • 用户可见的访问您的私有播放列表。

需要playlist-read-private作用域的端点

  • 检查用户是否遵循播放列表
  • 获取当前用户播放列表的列表
  • 获取用户播放列表的列表

虽然user-library-read范围似乎没有提供对播放列表的访问。

来源:https://developer.spotify.com/documentation/general/guides/scopes/#user-library-read

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54259824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档