summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorDennis Kobert <dennis@kobert.dev>2020-01-29 04:43:32 +0100
committerDennis Kobert <dennis@kobert.dev>2020-01-29 04:43:32 +0100
commit4878b00ba634ed9f4eeeffc1d488a5702f9383d9 (patch)
tree578949a1eeb78bcd3841c291f7fcb9015956f380 /src/main.rs
Initial commit
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..1bd3417
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,52 @@
+use rspotify::spotify::client::Spotify;
+use rspotify::spotify::oauth2::{SpotifyClientCredentials, SpotifyOAuth};
+use rspotify::spotify::util::get_token;
+
+fn main() {
+ // Set client_id and client_secret in .env file or
+ // export CLIENT_ID="your client_id"
+ // export CLIENT_SECRET="secret"
+ // export REDIRECT_URI=your-direct-uri
+
+ // Or set client_id, client_secret,redirect_uri explictly
+ // let oauth = SpotifyOAuth::default()
+ // .client_id("this-is-my-client-id")
+ // .client_secret("this-is-my-client-secret")
+ // .redirect_uri("http://localhost:8888/callback")
+ // .build();
+
+ let mut spotify_oauth = SpotifyOAuth::default()
+ .scope("playlist-read-private, playlist-read-collaborative")
+ .build();
+ match get_token(&mut spotify_oauth) {
+ Some(token_info) => {
+ let client_credential = SpotifyClientCredentials::default()
+ .token_info(token_info)
+ .build();
+
+ // Or set client_id and client_secret explictly
+ // let client_credential = SpotifyClientCredentials::default()
+ // .client_id("this-is-my-client-id")
+ // .client_secret("this-is-my-client-secret")
+ // .build();
+ let spotify = Spotify::default()
+ .client_credentials_manager(client_credential)
+ .build();
+ //this is my(samray's) user_id, so just change
+ // user_id to yours, or you will get a 403 forbidden error
+ let user_id = "d-kobert";
+ let playlists = spotify.user_playlists(user_id, Some(10), None);
+ for playlist in playlists.unwrap().items {
+ println!("{:?}", playlist.name);
+ for track in spotify
+ .user_playlist_tracks(user_id, &playlist.id, None, Some(2), None, None)
+ .unwrap()
+ .items
+ {
+ println!("{:?}", track.track.name);
+ }
+ }
+ }
+ None => println!("auth failed"),
+ };
+}