python - 使用 spotipy 和 Spotify Web API 时令牌不会刷新
问题描述
我正在尝试使用Spotipy 文档中的代码来查看客户端授权代码流是如何工作的。起初它有效,但过了一段时间我收到此错误:无法刷新令牌。响应状态代码: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'])
解决方案
您需要刷新访问代码。
您可以在此处的 spotipy 库中执行此操作 https://spotipy.readthedocs.io/en/2.16.1/?highlight=refresh#spotipy.oauth2.SpotifyOAuth.refresh_access_token
这就是为什么您通常会收到 400 原因:错误请求 | 403原因:禁止
推荐阅读
- python - python中opencv拼接器类的高级实现
- node.js - AWS弹性Beanstalk / nginx:connect()失败(111:连接被拒绝
- angular - 使用 httpclient 和 formdata 请求的资源上不存在“Access-Control-Allow-Origin”标头
- firebase - firebase函数部署崩溃的原因是什么
- python - 将数据添加到数据库时出现 Mongoengine 错误
- sql - 执行不区分大小写的表达式的最有效方法是什么?
- c# - 如何使用 C# 在 Unity 中以编程方式模拟 android 后退按钮按下
- api - 谷歌+ REST API。有什么方法可以从个人资料 URL 获取帐户 ID?
- python-3.x - 使用 yaml 覆盖命名空间
- log4net - 无法以编程方式配置 log4net Logger