Crates.io | spotify-rs |
lib.rs | spotify-rs |
version | 0.3.14 |
source | src |
created_at | 2023-08-02 23:52:41.074739 |
updated_at | 2024-08-11 19:01:45.095732 |
description | A Rust wrapper for the Spotify API. |
homepage | |
repository | https://github.com/Bogpan/spotify-rs |
max_upload_size | |
id | 933245 |
size | 173,079 |
spotify-rs is a Rust wrapper for the Spotify API.
It has full API coverage and supports all the authorisation flows (except for the implicit grant flow).
Usage example:
use spotify_rs::{AuthCodeClient, AuthCodeFlow, RedirectUrl};
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// This should match the redirect URI you set in your app's settings
let redirect_url = RedirectUrl::new("redirect_url".to_owned())?;
let auto_refresh = true;
let scopes = vec!["user-library-read", "playlist-read-private"];
let auth_code_flow = AuthCodeFlow::new("client_id", "client_secret", scopes);
// Redirect the user to this URL to get the auth code and CSRF token
let (client, url) = AuthCodeClient::new(auth_code_flow, redirect_url, auto_refresh);
// They will then have to be redirected to the `redirect_url` you specified,
// with those two parameters present in the URL
// Finally, exchange the auth code for an access token
let mut spotify = client.authenticate("auth_code", "csrf_token").await?;
// Get an album with the specified ID (requires no scopes to be set)
let album = spotify.album("album_id").get().await?;
// The `album` method returns a builder with optional parameters you can set
// For example, this sets the market to "GB".
let album_gb = spotify.album("album_id").market("GB").get().await?;
// Get 5 of the current user's playlists (requires the playlist-read-private scope)
let user_playlists = spotify.current_user_playlists().limit(5).get().await?;
Ok(())
}
spotify-rs is dual-licensed under Apache 2.0 and MIT terms.