-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from ramsayleung/auth-rewrite-part4
- Loading branch information
Showing
23 changed files
with
511 additions
and
879 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use rspotify::{ | ||
model::{AdditionalType, Country, Market}, | ||
prelude::*, | ||
scopes, AuthCodeSpotify, Credentials, OAuth, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
// You can use any logger for debugging. | ||
env_logger::init(); | ||
|
||
// Set RSPOTIFY_CLIENT_ID, RSPOTIFY_CLIENT_SECRET and | ||
// RSPOTIFY_REDIRECT_URI in an .env file or export them manually: | ||
// | ||
// export RSPOTIFY_CLIENT_ID="your client_id" | ||
// export RSPOTIFY_CLIENT_SECRET="secret" | ||
// | ||
// 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: "this-is-my-client-secret".to_string() | ||
// }; | ||
// ``` | ||
let creds = Credentials::from_env().unwrap(); | ||
|
||
// Or set the redirect_uri explictly: | ||
// | ||
// ``` | ||
// let oauth = OAuth { | ||
// redirect_uri: "http://localhost:8888/callback".to_string(), | ||
// scope: scopes!("user-read-recently-played"), | ||
// ..Default::default(), | ||
// }; | ||
// ``` | ||
let oauth = OAuth::from_env(scopes!("user-read-currently-playing")).unwrap(); | ||
|
||
let mut spotify = AuthCodeSpotify::new(creds, oauth); | ||
|
||
// Obtaining the access token | ||
let url = spotify.get_authorize_url(false).unwrap(); | ||
spotify.prompt_for_token(&url).await.unwrap(); | ||
|
||
// Running the requests | ||
let market = Market::Country(Country::Spain); | ||
let additional_types = [AdditionalType::Episode]; | ||
let artists = spotify | ||
.current_playing(Some(&market), Some(&additional_types)) | ||
.await; | ||
|
||
println!("Response: {:?}", artists); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use rspotify::{prelude::*, scopes, AuthCodePkceSpotify, Credentials, OAuth}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
// You can use any logger for debugging. | ||
env_logger::init(); | ||
|
||
// Set RSPOTIFY_CLIENT_ID, RSPOTIFY_CLIENT_SECRET and | ||
// RSPOTIFY_REDIRECT_URI in an .env file or export them manually: | ||
// | ||
// export RSPOTIFY_CLIENT_ID="your client_id" | ||
// export RSPOTIFY_CLIENT_SECRET="secret" | ||
// | ||
// 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: "this-is-my-client-secret".to_string() | ||
// }; | ||
// ``` | ||
let creds = Credentials::from_env().unwrap(); | ||
|
||
// Or set the redirect_uri explictly: | ||
// | ||
// ``` | ||
// let oauth = OAuth { | ||
// redirect_uri: "http://localhost:8888/callback".to_string(), | ||
// scope: scopes!("user-read-recently-played"), | ||
// ..Default::default(), | ||
// }; | ||
// ``` | ||
let oauth = OAuth::from_env(scopes!("user-read-recently-played")).unwrap(); | ||
|
||
let mut spotify = AuthCodePkceSpotify::new(creds, oauth); | ||
|
||
// Obtaining the access token | ||
let url = spotify.get_authorize_url().unwrap(); | ||
spotify.prompt_for_token(&url).await.unwrap(); | ||
|
||
// Running the requests | ||
let history = spotify.current_playback(None, None::<Vec<_>>).await; | ||
|
||
println!("Response: {:?}", history); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.