2015-09-28 28 views
4

我一直在试图与spotipy验证,使播放列表等Spotipy尝试验证通过OAuth

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. 

我去该网址,这是一个错误,我把它发回到命令行,它的错误。我不知道为什么这个库这样做,所有其他人通常会做用户名,密码,客户端ID和客户端密码。出于某种原因,这一个让你走了一步。一些帮助将不胜感激。我正在使用所有正确的信息。我不确定这个重定向url是什么,也许这是导致问题的原因?

回答

0

请按照此link获取您的客户端ID,秘密和回调uri。然后确保你在prompt_for_user_token调用正确设置这些参数

这个人让你去一个额外的步骤出于某种原因

的原因额外的步骤是你的URL得到的回应包括代码和状态变量,这些变量又被用来获取访问令牌。然后,您最终使用Spotify Web API与这些令牌。你会更好地了解这个故事,如果你检查official authorization guide

+1

尝试了这一点,我得到了一个页面,用于说明错误,我将网址粘贴回去,它说不好的请求。你必须有一个高级账户才能访问api或其他东西吗? – Eigenvalue

+0

不,我不。你是否设置了本地服务器?(localhost) – woryzower

+1

我不确定你的意思。为什么你需要一个本地服务器? – Eigenvalue

相关问题