forked from ramsayleung/rspotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_creds.rs
39 lines (33 loc) · 1.34 KB
/
client_creds.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use rspotify::{model::AlbumId, prelude::*, ClientCredsSpotify, Credentials};
#[tokio::main]
async fn main() {
// You can use any logger for debugging.
env_logger::init();
// Set RSPOTIFY_CLIENT_ID and RSPOTIFY_CLIENT_SECRET in an .env file (after
// enabling the `env-file` feature) or export them manually:
//
// export RSPOTIFY_CLIENT_ID="your client_id"
// export RSPOTIFY_CLIENT_SECRET="secret"
// export RSPOTIFY_REDIRECT_URI="your redirect uri"
//
// These will then be read with `from_env`.
//
// Otherwise, set client_id and client_secret explictly:
//
// ```
// let creds = Credentials {
// id: "this-is-my-client-id".to_string(),
// secret: Some("this-is-my-client-secret".to_string())
// };
// ```
let creds = Credentials::from_env().unwrap();
let spotify = ClientCredsSpotify::new(creds);
// Obtaining the access token. Requires to be mutable because the internal
// token will be modified. We don't need OAuth for this specific endpoint,
// so `...` is used instead of `prompt_for_user_token`.
spotify.request_token().await.unwrap();
// Running the requests
let birdy_uri = AlbumId::from_uri("spotify:album:0sNOF9WDwhWunNAHPD3Baj").unwrap();
let albums = spotify.album(birdy_uri, None).await;
println!("Response: {albums:#?}");
}