2017-11-19 8 views
0

Spotify API를 호출하고 클라이언트 ID 및 암호가있는 앱을 설정하려고합니다. (구체적인 밖으로 차단과) 여기 내 코드의 예 : 내 URL이 정확히 내 스포티 파이 앱 개발 페이지에 등록되어 것과 동일한 지 확인했습니다, 나는 클라이언트 ID를 추가 한INVOTENT_CLIENT를 사용하여 API 호출을 승인하려고 시도했습니다.

import spotipy 
import spotipy.util as util 
from spotipy.oauth2 import SpotifyClientCredentials 

cid ="xx" 
secret = "xx" 
username = "xx" 

client_credentials_manager = SpotifyClientCredentials(client_id=cid, client_secret=secret) 
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) 

scope = 'user-library-read playlist-read-private' 
token = util.prompt_for_user_token(username,scope,client_id='http://localhost:8888/callback/',client_secret='http://localhost:8888/callback/',redirect_uri='http://localhost:8888/callback/') 

if token: 
    sp = spotipy.Spotify(auth=token) 
else: 
    print("Can't get token for", username) 
cache_token = token.get_access_token() 

sp = spotipy.Spotify(cache_token) 
currentfaves = sp.current_user_top_tracks(limit=20, offset=0, time_range='medium_term') 

print(currentfaves) 

, 환경 변수에 URI와 클라이언트 비밀 키를 리디렉션합니다.

지금까지 (https://accounts.spotify.com/authorize?client_id=http%3A%2F%2Flocalhost%3A8888%2Fcallback%2F&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8888%2Fcallback%2F&scope=playlist-read-private+user-library-read) 별도의 탭이 열렸지 만 해당 페이지에서 'INVALID_CLIENT : 잘못된 클라이언트'만 표시됩니다. 이 작업을 수행하려면 어떻게해야합니까?

+0

클라이언트 ID 및 클라이언트 비밀 번호에 대한 리디렉션 URI를 입력합니다. 그 값을 조정하십시오 – Mangohero1

답변

0
token = util.prompt_for_user_token(username,scope,client_id='http://localhost:8888/callback/',client_secret='http://localhost:8888/callback/',redirect_uri='http://localhost:8888/callback/') 

리디렉션 uri를 클라이언트 ID 및 비밀번호로 복사 했으므로 여기에 오타가 있습니까?

+0

이것은 그 것이었다! 고맙습니다! –