ramsayleung / rspotify

Spotify Web API SDK implemented on Rust
MIT License
639 stars 122 forks source link

Json Parsing error internal #489

Open Jacob-Tate opened 2 months ago

Jacob-Tate commented 2 months ago

Describe the bug When attempting to use the show query code I get the following error this doesnt occur on the track search

To Reproduce

let creds = Credentials::new("redacted","redacted");
let client = ClientCredsSpotify::new(creds);
client.request_token().await.unwrap();

let show_query = "love";
let result = client.search(show_query, SearchType::Show, None, None, Some(10), None).await;
match result {
     Ok(show) => println!("Searched show: {show:?}"),
     Err(err) => println!("Search error! {err:?}"),
}

Log/Output data Search error! ParseJson(Error("invalid type: null, expected struct SimplifiedShow", line: 4, column: 20))

ramsayleung commented 1 month ago

I can reproduce this problem with curl:

·> curl --request GET \
  --url 'https://api.spotify.com/v1/search?limit=10&q=love&type=show' \
  --header 'Authorization: Bearer MyToken'
{
  "shows" : {
    "href" : "https://api.spotify.com/v1/search?query=love&type=show&offset=0&limit=10",
    "items" : [ null, null, null, null, null, null, null, null, null, null ],
    "limit" : 10,
    "next" : "https://api.spotify.com/v1/search?query=love&type=show&offset=10&limit=10",
    "offset" : 0,
    "previous" : null,
    "total" : 209
  }
}%

According to the Spotify's document:

If a valid user access token is specified in the request header, the country associated with the user account will take priority over this parameter. Note: If neither market or user country are provided, the content is considered unavailable for the client. Users can view the country that is associated with their account in the account settings.

You have not specified any country in your request, it means Spotify was using the country associated with your account, if you haven't set a country in your account setting, no show is available for you, so it return list of null.

In order to fix the above problem, you could simply specify a country like market=US