我正在尝试使用 Spotipy docs 中的代码来查看客户端授权代码流的工作原理。它起初有效,但过了一会儿我收到此错误:无法刷新令牌。响应状态代码:400 原因:错误请求。除了将客户端凭据添加到代码中之外,我根本没有编辑文档中的代码。谢谢! 这是我的代码:
import spotipy
from spotipy.oauth2 import SpotifyOAuth
scope = "user-library-read"
client_id='xxxxxxx'
client_secret='xxxxxx'
redirect_uri = "http://localhost:5000/callback"
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope,client_id=client_id,client_secret=client_secret,redirect_uri=redirect_uri))
results = sp.current_user_saved_tracks()
for idx, item in enumerate(results['items']):
track = item['track']
print(idx, track['artists'][0]['name'], " – ", track['name'])
答案 0 :(得分:0)
您需要刷新访问代码。
您可以在此处按照 spotipy 库执行此操作 https://spotipy.readthedocs.io/en/2.16.1/?highlight=refresh#spotipy.oauth2.SpotifyOAuth.refresh_access_token
这就是为什么你通常会得到 400 Reason: Bad Request | 403原因:禁止