2015-09-28 26 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

相關問題