[GH-ISSUE #719] Authenticating Spotipy for a single dedicated account #430

Closed
opened 2026-02-27 23:22:36 +03:00 by kerem · 3 comments
Owner

Originally created by @lucs100 on GitHub (Aug 21, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/719

I apologize in advance because I'm pretty sure this has been sorta asked before but I was having trouble getting started. At the moment my use case for Spotipy only involves interacting with a single dedicated account that I own, and essentially allows (only a few friends can interface with it so I won't be too overrun with requests or anything) multiple people to collaborate on a playlist in a roundabout way (I'm aware that this is a feature in Spotify already, but I wanted to create my own implementation of it). Therefore, I only need to authenticate access to that user account 'permanently' (I'm vaguely aware of tokens expiring after an hour, needing to be refreshed, etc., I should be able to deal with that later).

However, it seems like I'll have to go through OAuth for this, or generate a token in my program to use later. Having only surface level Python experience, I am thoroughly confused on how I'd go about doing this.

My current code to try and authenticate my account, which is admittedly copy-pasted boilerplate, looks like this:

# get client id, secret, and dedicated account id through .env (above these)

client_credentials_manager = SpotifyClientCredentials(client_id=cid, client_secret=secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
token = client_credentials_manager.get_access_token()

I know this is all-around horrible practice when asking for programming assistance, but I am just absolutely lost on where to go from here. I assume once my sp instance is 'authenticated' I'll be able to use it to make requests/posts, but I can't seem to figure out how to either use OAuth to authenticate my dedicated account for use, or how to generate a token through Spotipy. The relevant documentation is rather confusing for me as well - I assume I'd have to use authorization code flow, but the implementation doesn't seem to make much sense to me.

Apologies again for taking the lazier way out, but a starting point would be massively appreciated. 😅

Originally created by @lucs100 on GitHub (Aug 21, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/719 I apologize in advance because I'm pretty sure this has been sorta asked before but I was having trouble getting started. At the moment my use case for Spotipy only involves interacting with a single dedicated account that I own, and essentially allows (only a few friends can interface with it so I won't be too overrun with requests or anything) multiple people to collaborate on a playlist in a roundabout way (I'm aware that this is a feature in Spotify already, but I wanted to create my own implementation of it). Therefore, I only need to authenticate access to that user account 'permanently' (I'm vaguely aware of tokens expiring after an hour, needing to be refreshed, etc., I should be able to deal with that later). However, it seems like I'll have to go through OAuth for this, or generate a token in my program to use later. Having only surface level Python experience, I am thoroughly confused on how I'd go about doing this. My current code to try and authenticate my account, which is admittedly copy-pasted boilerplate, looks like this: ```python # get client id, secret, and dedicated account id through .env (above these) client_credentials_manager = SpotifyClientCredentials(client_id=cid, client_secret=secret) sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) token = client_credentials_manager.get_access_token() ``` I know this is all-around horrible practice when asking for programming assistance, but I am just absolutely lost on where to go from here. I assume once my `sp` instance is 'authenticated' I'll be able to use it to make requests/posts, but I can't seem to figure out how to either use OAuth to authenticate my dedicated account for use, or how to generate a token through Spotipy. The [relevant documentation](https://spotipy.readthedocs.io/en/2.19.0/#authorization-code-flow) is rather confusing for me as well - I assume I'd have to use authorization code flow, but the implementation doesn't seem to make much sense to me. Apologies again for taking the lazier way out, but a starting point would be massively appreciated. 😅
kerem 2026-02-27 23:22:36 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@stephanebruckert commented on GitHub (Aug 21, 2021):

Since you plan to do user actions, you will need SpotifyOAuth instead of SpotifyClientCredentials. Please check the 2 examples in the README to see the difference https://github.com/plamere/spotipy#quick-start

I'm vaguely aware of tokens expiring after an hour, needing to be refreshed, etc.,

You don't have to worry about that, spotipy takes care of it.

Once you've got the second example in the README working (with the help of Getting Started), the rest is not difficult: you will want to replace sp.current_user_saved_tracks() by any other method from the doc that is useful to you.

The docs are probably not perfect, so please feel free to bring improvements while you are going through it!

<!-- gh-comment-id:903165962 --> @stephanebruckert commented on GitHub (Aug 21, 2021): Since you plan to do user actions, you will need `SpotifyOAuth` instead of `SpotifyClientCredentials`. Please check the 2 examples in the README to see the difference https://github.com/plamere/spotipy#quick-start > I'm vaguely aware of tokens expiring after an hour, needing to be refreshed, etc., You don't have to worry about that, spotipy takes care of it. Once you've got the second example in the README working (with the help of [Getting Started](https://spotipy.readthedocs.io/en/2.19.0/#getting-started)), the rest is not difficult: you will want to replace `sp.current_user_saved_tracks()` by [any other method from the doc](https://spotipy.readthedocs.io/en/2.19.0/#api-reference) that is useful to you. The docs are probably not perfect, so please feel free to bring improvements while you are going through it!
Author
Owner

@lucs100 commented on GitHub (Aug 21, 2021):

Seems to be working perfectly. My test method went through once I sorted everything out. Thanks so much for the pointer in the right direction, I'll close the issue now.

<!-- gh-comment-id:903174012 --> @lucs100 commented on GitHub (Aug 21, 2021): Seems to be working perfectly. My test method went through once I sorted everything out. Thanks so much for the pointer in the right direction, I'll close the issue now.
Author
Owner

@stephanebruckert commented on GitHub (Aug 21, 2021):

'mazing!

<!-- gh-comment-id:903186416 --> @stephanebruckert commented on GitHub (Aug 21, 2021): 'mazing!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#430
No description provided.