python – Spotipy试图用oauth验证
发布时间:2020-12-20 13:07:30 所属栏目:Python 来源:网络整理
导读:我一直试图通过spotipy验证制作播放列表等. import spotipyimport spotipy.util as utilclass buildPlayList(): def __init__(self,name): scope = 'playlist-modify-public' self.username=name token = util.prompt_for_user_token(self.username,scope,cl
我一直试图通过spotipy验证制作播放列表等.
import spotipy import spotipy.util as util class buildPlayList(): def __init__(self,name): scope = 'playlist-modify-public' self.username=name token = util.prompt_for_user_token(self.username,scope,client_id='',client_secret='',redirect_uri='http://example.com/callback/') self.sp = spotipy.Spotify(auth=token) print self.sp.current_user() def make_and_build(self): pass x=buildPlayList("myname") 我运行它然后我得到这个: User authentication requires interaction with your web browser. Once you enter your credentials and give authorization,you will be redirected to a url. Paste that url you were directed to to complete the authorization. 我转到URL,这是一个错误,我把它发回到命令行,它出错了.我不知道为什么这个库会这样做,所有其他人通常都会使用用户名,密码,客户端ID和客户端密码.由于某种原因,这个让你走得更远.一些帮助将不胜感激.我正在使用所有正确的信息.我不确定这个重定向网址是什么,也许这会导致问题? 解决方法
按照此
link获取您的客户端ID,秘密和回调uri.然后确保在prompt_for_user_token调用中正确设置这些参数
额外步骤的原因是您使用url获得的响应包括代码和状态变量,而这些变量又用于获取访问令牌.然后,您最终将Spotify Web API与这些令牌一起使用.如果你查看official authorization guide,你会更好地理解这个故事 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |