Perform Spotify authorization

This commit is contained in:
2025-06-23 15:26:42 -04:00
parent fc36b58897
commit fe8041c00d

View File

@ -1,8 +1,34 @@
use rspotify::{
prelude::*,
scopes, AuthCodeSpotify, Credentials, OAuth,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenvy::dotenv()?;
println!("Hello, world!");
let client_id = std::env::var("SPOTIFY_CLIENT_ID")
.expect("SPOTIFY_CLIENT_ID must be set in .env file or as an environment variable");
let client_secret = std::env::var("SPOTIFY_CLIENT_SECRET")
.expect("SPOTIFY_CLIENT_SECRET must be set in .env file or as an environment variable");
let redirect_uri = std::env::var("SPOTIFY_REDIRECT_URI")
.unwrap_or("http://127.0.0.1:8888/callback".to_string());
let credentials = Credentials::new(&client_id, &client_secret);
let oauth = OAuth {
redirect_uri,
scopes: scopes!(),
..Default::default()
};
let spotify = AuthCodeSpotify::new(credentials, oauth);
println!("Performing authorization...");
let url = spotify.get_authorize_url(false)?;
spotify.prompt_for_token(&url).await?;
Ok(())
}