【发布时间】:2021-04-26 14:33:22
【问题描述】:
我尝试了标准方法(在主页上有描述),但我需要在没有网络浏览器的情况下登录。我该怎么做?
【问题讨论】:
-
不确定我是否理解您的问题,但您可能想看看他们在 spotifyd(开源 spotify 客户端守护程序)中做了什么
-
谢谢。我去看看
我尝试了标准方法(在主页上有描述),但我需要在没有网络浏览器的情况下登录。我该怎么做?
【问题讨论】:
您可以使用 Spotify 的 python 库之一,例如:https://github.com/plamere/spotipy
在 repo 中,您可以看到一个带有用户身份验证的示例
import spotipy
from spotipy.oauth2 import SpotifyOAuth
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="YOUR_APP_CLIENT_ID",
client_secret="YOUR_APP_CLIENT_SECRET",
redirect_uri="YOUR_APP_REDIRECT_URI",
scope="user-library-read"))
results = sp.current_user_saved_tracks()
for idx, item in enumerate(results['items']):
track = item['track']
print(idx, track['artists'][0]['name'], " – ", track['name'])
(需要先安装库:pip install spotipy)
另一个python库https://tekore.readthedocs.io/en/stable/:
import tekore as tk
conf = (client_id, client_secret, redirect_uri)
token = tk.prompt_for_user_token(*conf, scope=tk.scope.every)
spotify = tk.Spotify(token)
tracks = spotify.current_user_top_tracks(limit=10)
spotify.playback_start_tracks([t.id for t in tracks.items])
【讨论】: