-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathpagination_sync.rs
36 lines (30 loc) · 1.14 KB
/
pagination_sync.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
//! This example shows how automatic pagination works for synchronous clients.
//!
//! Synchronous iteration is easier than the async method shown in the
//! `current_user_saved_tracks` example, but you can also use:
//!
//! ```
//! while let Some(item) = stream.next() {
//! // ...
//! }
//! ```
use rspotify::{prelude::*, scopes, AuthCodeSpotify, Credentials, OAuth};
fn main() {
// You can use any logger for debugging.
env_logger::init();
// May require the `env-file` feature enabled if the environment variables
// aren't configured manually.
let creds = Credentials::from_env().unwrap();
let oauth = OAuth::from_env(scopes!("user-library-read")).unwrap();
let spotify = AuthCodeSpotify::new(creds, oauth);
// Obtaining the access token
let url = spotify.get_authorize_url(false).unwrap();
// This function requires the `cli` feature enabled.
spotify.prompt_for_token(&url).unwrap();
// Typical iteration, no extra boilerplate needed.
let stream = spotify.current_user_saved_tracks(None);
println!("Items:");
for item in stream {
println!("* {}", item.unwrap().track.name);
}
}