19个版本

0.3.14 2024年8月11日
0.3.13 2024年7月27日
0.3.10 2023年12月31日
0.3.9 2023年9月1日
0.1.3 2023年8月4日

#151 in HTTP客户端

Download history 1/week @ 2024-05-29 3/week @ 2024-06-05 48/week @ 2024-07-17 269/week @ 2024-07-24 37/week @ 2024-07-31 96/week @ 2024-08-07

每月450次下载

MIT/Apache

155KB
4K SLoC

crates.io docs.rs

spotify-rs

spotify-rs是Spotify API的Rust包装器。

它覆盖了全部API,并支持所有授权流程(除隐式授权流程外)。

使用示例

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根据Apache 2.0MIT条款进行双重授权。

依赖项

~6–21MB
~284K SLoC