[GH-ISSUE #779] How to check whether client id and client secret are correct before actually calling the API? #478

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

Originally created by @clemwo on GitHub (Feb 2, 2022).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/779

In my program I would like to check whether the supplied client id and client secret are correct before actually using them to add songs to playlists, etc.
Is there are special function to check whether stuff is correct?
My issue is that I would like to check the credentials at the start of the program and not when it is running and trying to call the API with incorrect credentials.

My code looks like this:

auth_manager = spotipy.oauth2.SpotifyOAuth(scope="playlist-modify-public playlist-modify-private "
                                                     "playlist-read-private",
                                               client_id='incorrect_id',
                                               client_secret='false_secret',
                                               redirect_uri='http://localhost:8888/callback')
sp = spotipy.Spotify(auth_manager=auth_manager)

# Here I would like to check whether client_id and client_secret are correct
# my current workaround is to just use me()
    try:
        spotipy_client.me()
    except SpotifyOauthError:
        print('Ya dun goofed')

This feels very hacky and I would like to know whether I can simply use a function to check.

Originally created by @clemwo on GitHub (Feb 2, 2022). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/779 In my program I would like to check whether the supplied client id and client secret are correct before actually using them to add songs to playlists, etc. Is there are special function to check whether stuff is correct? My issue is that I would like to check the credentials at the start of the program and not when it is running and trying to call the API with incorrect credentials. My code looks like this: ```python auth_manager = spotipy.oauth2.SpotifyOAuth(scope="playlist-modify-public playlist-modify-private " "playlist-read-private", client_id='incorrect_id', client_secret='false_secret', redirect_uri='http://localhost:8888/callback') sp = spotipy.Spotify(auth_manager=auth_manager) # Here I would like to check whether client_id and client_secret are correct # my current workaround is to just use me() try: spotipy_client.me() except SpotifyOauthError: print('Ya dun goofed') ``` This feels very hacky and I would like to know whether I can simply use a function to check.
kerem 2026-02-27 23:22:51 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@Peter-Schorn commented on GitHub (Feb 2, 2022):

The only way to check if the client id and secret are correct is to attempt to go through the authorization process. The web API is designed with the assumption that the client id and secret are hardcoded into the program (or, at least, they don't change at runtime) by the developer of that program, who knows if the values are correct.

<!-- gh-comment-id:1028327279 --> @Peter-Schorn commented on GitHub (Feb 2, 2022): The only way to check if the client id and secret are correct is to attempt to go through the authorization process. The web API is designed with the assumption that the client id and secret are hardcoded into the program (or, at least, they don't change at runtime) by the developer of that program, who knows if the values are correct.
Author
Owner

@clemwo commented on GitHub (Feb 2, 2022):

Thanks for the reply. So my somewhat 'hacky' solution is the best one under the circumstances, right?

<!-- gh-comment-id:1028328729 --> @clemwo commented on GitHub (Feb 2, 2022): Thanks for the reply. So my somewhat 'hacky' solution is the best one under the circumstances, right?
Author
Owner

@Peter-Schorn commented on GitHub (Feb 2, 2022):

Yes.

<!-- gh-comment-id:1028449682 --> @Peter-Schorn commented on GitHub (Feb 2, 2022): Yes.
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#478
No description provided.