使用下面的代码,我可以为我的用户检索一个playlists对象,但是items条目的列表是空的。我有几百个播放列表,所以我一定是在这段代码中遗漏了什么。
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产出如下:
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})发布于 2019-01-24 19:01:36
这似乎很管用。但是它不返回播放列表文件夹。我还没有发现任何关于这类事情的污点。
#!/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)发布于 2019-01-23 18:33:50
我认为library和playlist是可以访问的不同资源。
您可能需要应用playlist-read-private作用域。
playlist-read-private
需要playlist-read-private作用域的端点
虽然user-library-read范围似乎没有提供对播放列表的访问。
来源:https://developer.spotify.com/documentation/general/guides/scopes/#user-library-read
https://stackoverflow.com/questions/54259824
复制相似问题