Reputation: 223
I want to create a simple app that tracks how many minutes I listen to music on Spotify every day. To my knowledge, I need to use oAuth to receive this data (user-read-currently-playing). I am currently authenticating like this:
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)
I know that it works because if I run it on Windows where I have a graphical display, everything is just fine and I can get the redirect Url and the auth code from the browser the login page opens in. Is there any way to get this code on a headless linux machine?
Upvotes: 2
Views: 1211
Reputation: 223
I found a solution to this problem: Instead of using
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)
You can use
spotify = spotipy.Spotify(auth_manager=SpotifyOAuth(
client_id="id", client_secret="secret", redirect_uri="http://localhost:4466", scope=scope, open_browser=False, ))
This achives the same goal. To authenticate in a headless envirement, you can copy the cashed Auth from for example a windows machine to your Linux machine as long as they are both in the folder cmd is opened in.
Upvotes: 2