Expand description
§Spotify OAuth
An implementation of the Spotify Authorization Code Flow in Rust.
§Basic Example
use std::{io::stdin, str::FromStr, error::Error};
use spotify_oauth::{SpotifyAuth, SpotifyCallback, SpotifyScope};
#[async_std::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
// Setup Spotify Auth URL
let auth = SpotifyAuth::new_from_env("code".into(), vec![SpotifyScope::Streaming], false);
let auth_url = auth.authorize_url()?;
// Open the auth URL in the default browser of the user.
open::that(auth_url)?;
println!("Input callback URL:");
let mut buffer = String::new();
stdin().read_line(&mut buffer)?;
// Convert the given callback URL into a token.
let token = SpotifyCallback::from_str(buffer.trim())?
.convert_into_token(auth.client_id, auth.client_secret, auth.redirect_uri).await?;
println!("Token: {:#?}", token);
Ok(())
}
Structs§
- Spotify
Auth - Spotify Authentication
- Spotify
Callback - The Spotify Callback URL
- Spotify
Token - The Spotify Token object.
Enums§
- Spotify
Scope - Spotify Scopes for the API. This enum implements FromStr and ToString / Display through strum.
Functions§
- datetime_
to_ timestamp - Convert date and time to a unix timestamp.
- generate_
random_ string - Generate a random alphanumeric string with a given length.