Overview
The simplest authentication method for the Spotify SDK is using a direct access token. This approach is ideal for:- Quick prototyping and testing
- Short-lived applications
- Scenarios where you manually obtain tokens from the Spotify Developer Dashboard
- Server-side scripts with pre-generated tokens
Basic Usage
Creating a Client with Access Token
Using Context Managers
Async Support
Constructor Parameters
A valid Spotify access token. You can obtain one from the Spotify Developer Dashboard or through OAuth flows.
Request timeout in seconds.
Maximum number of retry attempts for failed requests. The SDK automatically retries on connection errors, timeouts, rate limits (429), and server errors (5xx).
Token Expiration Handling
Access tokens expire after 1 hour. When using direct access token authentication, you must handle expiration manually:For automatic token refresh, consider using ClientCredentials or AuthorizationCode authentication providers.
Getting an Access Token
Create a Spotify App
Visit the Spotify Developer Dashboard and create a new application.
Generate a Token
Use the Spotify Web API Console or implement an OAuth flow to generate an access token. For quick testing, you can use the Spotify Web API Console.
When to Use Access Token Authentication
Use access token authentication when:- Building quick prototypes or proof-of-concepts
- Running one-off scripts or data analysis tasks
- Testing API endpoints manually
- You have a secure way to refresh tokens externally
- Building production applications (use Client Credentials or Authorization Code instead)
- You need automatic token refresh
- You need to access user-specific endpoints (use Authorization Code flow)
- Your application runs continuously (tokens expire after 1 hour)
Related
- Client Credentials Flow - Automatic token refresh for app-only authentication
- Authorization Code Flow - User authentication with automatic refresh
- Error Handling - Handling authentication errors