login/
login.rs

1use flickr_api::{ApiKey, FlickrAPI};
2use std::error::Error;
3use std::io::{self, Write};
4
5fn prompt(message: &str) -> String {
6    // Create a new String to hold the user's input
7    let mut input = String::new();
8
9    // Print a prompt message to the console
10    print!("{message}");
11
12    // Ensure the prompt message is printed immediately
13    io::stdout().flush().ok();
14
15    // Read the user's input from standard input
16    io::stdin()
17        .read_line(&mut input)
18        .expect("Failed to read line");
19
20    // Remove the trailing newline character
21    input.trim().to_string()
22}
23
24#[tokio::main]
25async fn main() -> Result<(), Box<dyn Error>> {
26    let client = FlickrAPI::new(ApiKey {
27        key: prompt("API key: "),
28        secret: prompt("API secret: "),
29    })
30    .login()
31    .await?;
32
33    let user = client.test().login().await?;
34
35    println!("Successfully logged in as {} ({})", user.username, user.id);
36
37    Ok(())
38}