get_token.rs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. use std::env;
  2. use tokio_core::reactor::Core;
  3. use librespot::core::authentication::Credentials;
  4. use librespot::core::config::SessionConfig;
  5. use librespot::core::keymaster;
  6. use librespot::core::session::Session;
  7. const SCOPES: &str =
  8. "streaming,user-read-playback-state,user-modify-playback-state,user-read-currently-playing";
  9. fn main() {
  10. let mut core = Core::new().unwrap();
  11. let handle = core.handle();
  12. let session_config = SessionConfig::default();
  13. let args: Vec<_> = env::args().collect();
  14. if args.len() != 4 {
  15. println!("Usage: {} USERNAME PASSWORD CLIENT_ID", args[0]);
  16. }
  17. let username = args[1].to_owned();
  18. let password = args[2].to_owned();
  19. let client_id = &args[3];
  20. println!("Connecting..");
  21. let credentials = Credentials::with_password(username, password);
  22. let session = core
  23. .run(Session::connect(session_config, credentials, None, handle))
  24. .unwrap();
  25. println!(
  26. "Token: {:#?}",
  27. core.run(keymaster::get_token(&session, &client_id, SCOPES))
  28. .unwrap()
  29. );
  30. }