I tried the standard methods (which are described on the home page), but I need to log in without a web browser. How can I do this?
Asked
Active
Viewed 951 times
3
-
not sure I understood your question right, but you might want to take a look at what they did in spotifyd (open source spotify client daemon) – tbrugere Apr 26 '21 at 14:34
-
Thanks. I'll take a look – Антон Фикалис Apr 26 '21 at 14:36
1 Answers
0
You can use one of Spotify's python libraries, for example: https://github.com/plamere/spotipy
In the repo you can see an example with user authentication
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'])
(need to install the library first: pip install spotipy
)
Another python library 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])

Adam
- 299
- 1
- 4
- 19
-
According to the title OP uses spotipy... This means that your answer is fine, just the first sentence is not necessary... – Tomerikoo Apr 26 '21 at 14:42
-
1I also use this library. The problem is that the first time you start the program, it opens a web browser to log in. And I just need to log in without opening a web browser – Антон Фикалис Apr 26 '21 at 14:44