尝试使用Spotipy授权api调用时INVALID_CLIENT

时间:2017-11-19 16:53:13

标签: python api authorization spotipy

我正在尝试调用Spotify API并设置了应用程序/获取了我的客户端ID和密码。这是我的代码示例(特定内容被阻止):

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)

我确保我的网址与Spotify应用开发页面中注册的网址完全一致,并且我已将客户端ID,重定向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:无效的客户'。我可以做些什么/改变这项工作?

1 个答案:

答案 0 :(得分: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和密码?