Perform Spotify authorization
This commit is contained in:
28
src/main.rs
28
src/main.rs
@ -1,8 +1,34 @@
|
|||||||
|
use rspotify::{
|
||||||
|
prelude::*,
|
||||||
|
scopes, AuthCodeSpotify, Credentials, OAuth,
|
||||||
|
};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
dotenvy::dotenv()?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user