rspotify
rspotify copied to clipboard
Json Parsing error internal
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))
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
This problem should be fixed by this PR https://github.com/ramsayleung/rspotify/pull/526/files, you could consume the 0.15.0 to solve this problem.