我正在尝试调用 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)
我已确保我的 URL 与我在 Spotify 应用程序开发页面中注册的 URL 完全相同,并且我已将客户端 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:无效客户端”。我可以做/改变什么来完成这项工作?