Code: Select all
import spotipy
from spotipy.oauth2 import SpotifyOAuth
# Credentials from Spotify Developer Dashboard
CLIENT_ID = 'my_client_id'
CLIENT_SECRET = 'my_client_secret'
REDIRECT_URI = 'https://example.com:3000'
# Authenticate
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
redirect_uri=REDIRECT_URI,
scope="user-library-read"
))
# Test API call
results = sp.current_user_saved_tracks()
print("Fetched saved tracks successfully!")
< /code>
Wenn ich den Code ausführe, wird Safari zur Authentifizierung geöffnet. Nach der Genehmigung des Zugriffs erhalte ich diesen Fehler: < /p>
Using Python interpreter: /opt/anaconda3/bin/python
Fetching your saved tracks...
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.12/site-packages/spotipy/oauth2.py", line 527, in get_access_token
response.raise_for_status()
File "/opt/anaconda3/lib/python3.12/site-packages/requests/models.py", line 1024, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://accounts.spotify.com/api/token
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/-/Downloads/spotipy_new.py", line 26, in
results = sp.current_user_saved_tracks()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/lib/python3.12/site-packages/spotipy/client.py", line 1324, in current_user_saved_tracks
return self._get("me/tracks", limit=limit, offset=offset, market=market)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/lib/python3.12/site-packages/spotipy/client.py", line 327, in _get
return self._internal_call("GET", url, payload, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/lib/python3.12/site-packages/spotipy/client.py", line 251, in _internal_call
headers = self._auth_headers()
^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/lib/python3.12/site-packages/spotipy/client.py", line 242, in _auth_headers
token = self.auth_manager.get_access_token(as_dict=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/lib/python3.12/site-packages/spotipy/oauth2.py", line 533, in get_access_token
self._handle_oauth_error(http_error)
File "/opt/anaconda3/lib/python3.12/site-packages/spotipy/oauth2.py", line 117, in _handle_oauth_error
raise SpotifyOauthError(
spotipy.exceptions.SpotifyOauthError: error: invalid_client, error_description: Invalid client secret
Verifizierte Anmeldeinformationen: bestätigt Client_id und Client_secret genau mit dem Spotify -Entwickler -Dashboard übereinstimmen. Schrägstriche). /> Aktualisiert SpotIpy: Ran Pip Installation -Upgrade Spotipy Um sicherzustellen, dass ich in der neuesten Version bin. /> Zusätzliche Hinweise:
Der OAuth -Fluss beginnt korrekt (Safari öffnet sich und ich kann mich anmelden), aber der Fehler tritt während des Token -Austauschs auf. Fehler invaler_client Trotz meines Setups korrekt? Gibt es zusätzliche Debugging -Schritte oder -Korretiere, die ich versuchen kann, dies zu beheben?>