Spotify Web API와의 부분적 통합을 제공하는 Dart 라이브러리로, Flutter 애플리케이션이 Spotify의 음악 및 오디오 서비스와 상호작용할 수 있게 해줍니다. 완전하지는 않지만 사용자 데이터, 플레이리스트, 트랙 및 검색 기능에 접근하기 위한 기본 기능을 제공합니다. 음악 중심 앱을 개발하는 개발자를 위해 설계되었으며, Android, iOS, Web, macOS, Windows, Linux 등 여러 플랫폼을 지원합니다. 활발히 유지보수되고 오픈소스이므로 커뮤니티 기여가 가능합니다. Flutter 프로젝트에서 더 깊은 Spotify 통합을 시작하는 기반이 됩니다.
사용 사례
음악 앱 개발
사용자 플레이리스트 관리
트랙 및 아티스트 검색
Spotify 인증 흐름
오디오 콘텐츠 탐색
주요 기능
부분적인 Spotify Web API 지원
크로스 플랫폼 호환성
오픈소스이며 커뮤니티 주도
인증 통합
트랙 및 플레이리스트에 대한 기본 데이터 검색
적합한 대상
음악 앱을 개발하는 Flutter 개발자
Spotify 데이터 접근이 필요한 프로젝트
크로스 플랫폼 오디오 애플리케이션
초보자가 Spotify API 탐색 중
고려 사항
기능 세트가 불완전함
누락된 엔드포인트에 대한 수동 처리가 필요합니다
제한된 문서
외부 API 변경에 따라 달라짐
추가 검증 없이 생산 환경에 적합하지 않습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
spotify-dart
A Dart library for interfacing with the Spotify API.
Note: Related Artists, Audio Features, Audio Analysis, Featured Playlists, Category Playlists and Recommendation endpoints are deprecated by Spotify but still available in this library.
Quick Start
Simple Example (Client Credentials)
import'package:spotify/spotify.dart';
voidmain() async {
final credentials = SpotifyApiCredentials(clientId, clientSecret);
final spotify = SpotifyApi(credentials);
// Get artist infofinal artist = await spotify.artists.get('0OdUWJ0sBjDrqHygGUXeCF');
print(artist.name); // 'Band of Horses'// Search for tracksvar search = await spotify.search.get('metallica').first(2);
print(search.first.items); // List of albums, artists, tracks, etc.
}
Working with Pagination
Many endpoints return paginated results:
// Get all tracks from an albumvar tracks = await spotify.albums.getTracks(albumId).all();
// Get first N itemsvar featured = await spotify.playlists.featured.first(5);
// Stream through pagesawaitfor (var page in spotify.playlists.getUsersPlaylists(userId).stream()) {
print(page.items);
}
Authorization
This library supports multiple authorization flows:
Client Credentials Flow - For accessing public data (artists, albums, tracks, etc.)
Authorization Code Grant - For accessing user data and controlling playback
PKCE Support - Enhanced security for public clients
For detailed information on authorization flows, OAuth scopes, and advanced usage, see the wiki.
PKCE (Public Client) Authentication
For mobile apps and single-page applications that cannot securely store client secrets, use PKCE:
// Generate a secure code verifierfinal verifier = SpotifyApi.generateCodeVerifier();
// Create PKCE credentials (no client secret needed!)final credentials = SpotifyApiCredentials.pkce(
'your-client-id',
codeVerifier: verifier,
);
// Complete OAuth flowfinal grant = SpotifyApi.authorizationCodeGrant(credentials);
final authUri = grant.getAuthorizationUrl(redirectUri, scopes: scopes);
// ... redirect user, get authorization codefinal client = await grant.handleAuthorizationResponse(params);
final spotify = SpotifyApi.fromClient(client);
// Save credentials for later (including codeVerifier!)final creds = await spotify.getCredentials();
// Store creds.codeVerifier along with other credential fields// Restore laterfinal spotify = awaitSpotifyApi.asyncFromCredentials(restoredCreds);
See example/example_pkce.dart for a complete working example.
Features and bugs
Please file feature requests and bugs at the issue tracker.
Contributing
Contributions are welcome! Here's how to work on this project:
Run dart run build_runner build to generate serializers
Run dart run build_runner watch to continuously rebuild when files change
Code Quality
Before committing, ensure your code passes:
Formatting: dart format .
Analysis: dart analyze
Running Tests
Run the test suite:
dart test
Running Examples
To run the basic example:
dart run example/example.dart
You'll need to modify the file to include your Spotify client ID and secret.
For the authenticated example (accessing user data, playback control) run:
dart run example/example_auth.dart
This example will prompt you for a redirect URL and guide you through the OAuth flow to access features like currently playing tracks and available devices.