Python 如何在无头设备上使用oAuth和spotipy?
我想创建一个简单的应用程序,跟踪我每天在Spotify上听音乐的分钟数。据我所知,我需要使用oAuth来接收此数据(用户读取当前正在播放)。我目前正在进行如下身份验证:Python 如何在无头设备上使用oAuth和spotipy?,python,oauth,spotify,spotipy,Python,Oauth,Spotify,Spotipy,我想创建一个简单的应用程序,跟踪我每天在Spotify上听音乐的分钟数。据我所知,我需要使用oAuth来接收此数据(用户读取当前正在播放)。我目前正在进行如下身份验证: token = util.prompt_for_user_token("<username>", scope, client_id="<clientID>", client_secret="<client_secret>", redi
token = util.prompt_for_user_token("<username>", scope, client_id="<clientID>", client_secret="<client_secret>", redirect_uri="http://localhost:4466")
spotify = spotipy.Spotify(auth=token)
token=util.prompt\u for\u user\u token(“,scope,client\u id=”,client\u secret=”,redirect\u uri=”http://localhost:4466")
spotify=spotipy.spotify(auth=token)
我知道它是有效的,因为如果我在有图形显示的Windows上运行它,一切都很好,我可以从登录页面打开的浏览器中获取重定向Url和身份验证代码。有没有办法在无头linux机器上获取此代码?我找到了解决此问题的方法: 而不是使用
token = util.prompt_for_user_token("<username>", scope, client_id="<clientID>", client_secret="<client_secret>", redirect_uri="http://localhost:4466")
spotify = spotipy.Spotify(auth=token)
这实现了同样的目标。要在无头环境中进行身份验证,您可以将现金身份验证从例如windows计算机复制到Linux计算机,只要它们都在cmd中打开的文件夹中
spotify = spotipy.Spotify(auth_manager=SpotifyOAuth(
client_id="id", client_secret="secret", redirect_uri="http://localhost:4466", scope=scope, open_browser=False, ))