-
Notifications
You must be signed in to change notification settings - Fork 124
Closed
Labels
bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed
Description
Describe the bug
Whenever I try to use user_playlist_create
I get Error: http error: status code 400 Bad Request
. Other API calls work fine.
To Reproduce
Here is a minimum working example:
use anyhow::Result;
use rspotify::{prelude::*, scopes, AuthCodePkceSpotify, Config, Credentials, OAuth};
#[tokio::main]
async fn main() -> Result<()> {
env_logger::init();
let creds = Credentials::from_env().unwrap();
let oauth = OAuth::from_env(scopes!(
"playlist-read-collaborative",
"playlist-read-private",
"playlist-modify-public",
"playlist-modify-private"
))
.unwrap();
let config = Config {
token_cached: true,
token_refreshing: true,
..Default::default()
};
let mut spotify = AuthCodePkceSpotify::with_config(creds, oauth, config);
// The URL the user enters into the terminal
let url = spotify.get_authorize_url(None).unwrap();
match spotify.prompt_for_token(&url).await {
Ok(_) => (),
// If the token is too old, refresh it
// The unwrap still panics sometime and I'm not sure why
Err(_) => spotify.refresh_token().await.unwrap(),
}
let id = &spotify.me().await?.id;
spotify
.user_playlist_create(
id,
"this is a test",
Some(true),
Some(true),
Some("this is a test"),
)
.await?;
Ok(())
}
This panics with the error "Error: http error: status code 400 Bad Request". The API call spotify.me()
works fine.
Expected behavior
I expected the playlist to be created (or have some other error like a network error).
Log/Output data
Running with RUST_LOG=trace cargo run
produces the following:
[2022-07-25T13:11:39Z INFO rspotify::auth_code_pkce] Building auth URL
[2022-07-25T13:11:39Z INFO rspotify::auth_code_pkce] Generating PKCE codes
[2022-07-25T13:11:39Z INFO rspotify::clients::oauth] Reading auth token cache
[2022-07-25T13:11:39Z INFO rspotify::clients::base] Writing token cache
[2022-07-25T13:11:39Z INFO rspotify_http::reqwest] Making request RequestBuilder { method: GET, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("api.spotify.com")), port: None, path: "/v1/me/", query: None, fragment: None }, headers: {"authorization": "Bearer [not sure if I can show this]"} }
[2022-07-25T13:11:39Z DEBUG reqwest::connect] starting new connection: https://api.spotify.com/
[2022-07-25T13:11:40Z TRACE mio::poll] registering event source with poller: token=Token(0), interests=READABLE | WRITABLE
[2022-07-25T13:11:40Z TRACE want] signal: Want
[2022-07-25T13:11:40Z TRACE want] signal found waiting giver, notifying
[2022-07-25T13:11:40Z TRACE want] poll_want: taker wants!
[2022-07-25T13:11:40Z TRACE want] signal: Want
[2022-07-25T13:11:40Z TRACE want] signal: Want
[2022-07-25T13:11:40Z DEBUG reqwest::async_impl::client] response '200 OK' for https://api.spotify.com/v1/me/
[2022-07-25T13:11:40Z TRACE want] signal: Want
[2022-07-25T13:11:40Z INFO rspotify_http::reqwest] Making request RequestBuilder { method: POST, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("api.spotify.com")), port: None, path: "/v1/users/sergiogonzalo03/playlists", query: None, fragment: None }, headers: {"authorization": "Bearer [not sure if I can show this]", "content-type": "application/json"} }
[2022-07-25T13:11:40Z TRACE want] signal: Want
[2022-07-25T13:11:40Z TRACE want] signal: Want
[2022-07-25T13:11:40Z DEBUG reqwest::async_impl::client] response '400 Bad Request' for https://api.spotify.com/v1/users/sergiogonzalo03/playlists
[2022-07-25T13:11:40Z TRACE want] poll_want: taker wants!
[2022-07-25T13:11:40Z TRACE mio::poll] deregistering event source from poller
[2022-07-25T13:11:40Z TRACE want] signal: Closed
Additional context
N/A
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed