我有一个用于我认识的流媒体的 twitch 机器人,我正在尝试发出一个命令来显示他当前在 spotify 上收听的歌曲。
我找到了执行此操作的 Spotipy 库,但是我收到了无效的用户名错误,代码如下:
import spotipy
import spotipy.util as util
CLIENT_ID = 'xx'
CLIENT_SECRET = 'xx'
token = util.oauth2.SpotifyClientCredentials(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
cache_token = token.get_access_token()
sp = spotipy.Spotify(cache_token)
currentsong = sp.currently_playing()
print(currentsong)
在我的代码中,我填写了课程凭据。所以这段代码返回了这个错误:
Traceback (most recent call last):
File "/Users/Pascalschilp/Documents/spot/spotipy-master/lol.py", line 13, in <module>
currentsong = sp.currently_playing('spotify:user:passle')
File "/Users/Pascalschilp/Documents/spot/spotipy-master/spotipy/client.py", line 899, in currently_playing
return self._get("me/player/currently-playing", market = market)
File "/Users/Pascalschilp/Documents/spot/spotipy-master/spotipy/client.py", line 148, in _get
return self._internal_call('GET', url, payload, kwargs)
File "/Users/Pascalschilp/Documents/spot/spotipy-master/spotipy/client.py", line 126, in _internal_call
headers=r.headers)
spotipy.client.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/me/player/currently-playing?market=spotify%3Auser%3Apassle:
Invalid username
[Finished in 1.2s with exit code 1]
[shell_cmd: python -u "/Users/Pascalschilp/Documents/spot/spotipy-master/lol.py"]
[dir: /Users/Pascalschilp/Documents/spot/spotipy-master]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
我不确定为什么会出错。谁能指出我正确的方向?
另外/或者:我如何使用请求库进行承载身份验证?(我尝试在邮递员中手动执行请求并填写客户端 ID,它给了我这个错误:“消息”:“仅支持有效的不记名身份验证”)