python - 使用 Spotipy 的 invalid_client 错误和授权刷新令牌错误
问题描述
我正在为 Spotify API使用Spotipy包装器。目前,我正在排除的功能是用户身份验证(身份验证成功后,将创建一个具有指定名称的播放列表)
我正在使用授权代码流。
这是我的代码中与该问题相关的部分:
import spotipy
from clientcredentials import user_id, client_id, client_secret
from spotipy.oauth2 import SpotifyOAuth
USER_ID = user_id
SPOTIPY_CLIENT_ID = client_id
SPOTIPY_CLIENT_SECRET = client_secret
SPOTIPY_REDIRECT_URI = 'https://i.kym-cdn.com/entries/icons/original/000/027/475/Screen_Shot_2018-10-25_at_11.02.15_AM.png'
SCOPE = 'playlist-read-private,playlist-modify-private'
def auth_user(self):
auth_manager = SpotifyOAuth(
client_id=SPOTIPY_CLIENT_ID,
client_secret=SPOTIPY_CLIENT_SECRET,
redirect_uri=SPOTIPY_REDIRECT_URI,
scope=SCOPE
)
sp_authed = spotipy.Spotify(auth_manager=auth_manager)
return sp_authed
def create_playlist(self, authed):
new_playlist = authed.user_playlist_create(
USER_ID,
f"{self.artist_name} Favouritism",
public=False,
collaborative=False,
description=self.test_playlist_desc
)
return new_playlist
if __name__ == '__main__':
artist_name = input("Enter artist's name: ")
print(f"Creating playlist for {artist_name}...")
af = ArtistFavouritism(artist_name)
sp_authed = af.auth_user()
af.create_playlist(sp_authed)
我第一次运行这个,它工作得很好!但是在访问令牌过期后,需要刷新令牌。我试图找到一种方法来做到这一点,但在这个过程中可能会搞砸一些事情,所以我用相同的代码创建了一个新的应用程序。
(此外,我确实撤销了对我的应用程序的访问权限,因此我还在我的 Spotify 开发人员仪表板中创建了一个新应用程序,传输了必要的客户端参数并将重定向 URL 列入白名单)
当我尝试在这个新应用程序中再次运行代码时,它不起作用,并且出现此错误(已检查,这是 400 错误):
in refresh_access_token
raise SpotifyOauthError(
spotipy.oauth2.SpotifyOauthError: error: invalid_client, error_description: Invalid client
请帮忙!我在任何地方都找不到答案,这让我很生气,哈哈。任何建议将不胜感激!:)
解决方案
推荐阅读
- tomcat - 服务器上多个 tomcat 实例的 ansible 代码
- datetime - 与 Twig 的总日期
- node.js - 比较 nodejs 中的 2 个相同的 excel/ppt/csv 文件
- android - 如何在屏幕顶部显示 admob?
- html - Firefox html 有序列表编号被子列表弄乱了
- php - 如何修复“此路线不支持 GET 方法。支持的方法:POST 错误
- angular - 使用 Angular 7 和 NgxPagination 的服务器端分页
- c++ - 如何在没有 std::initializer_list 的情况下列出初始化模板类,使其具有固定大小
- javascript - 使用 Amazon SNS(节点)的推送通知
- python - 如何使用 pymongo 将精确匹配词传递给 mongodb 查询?