How to get audio features from tracks Spotify API C#

Viewed 63

I am building a program using C# and .WPF framework to create a personal recommendation system but I am having a problem when I get the audio tracks for multiple track Ids at once.

I have coded the below to request the audio features from the Spotify, and the Id array and Ids both work fine. If i change the RestRequest to a singular Id (Id[3]), the variable audio will be the features. Similiarly, if I put the request code in a for loop to do for each Id in the array each time the var audio would contain the audio features.

var client = new RestClient("https://api.spotify.com/v1/audio-features/");
            client.Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(accessToken, "Bearer");

            string[] Id = (string[])TrackIds.ToArray(typeof(string));
            string Ids = String.Join(",", Id);
            
                var request = new RestRequest($"?ids={Ids}", Method.Get);
                request.AddHeader("Content-Type", "application/json");
                var response = client.GetAsync(request).GetAwaiter().GetResult();
                var audio = JsonConvert.DeserializeObject<AudioFeatures>(response.Content);   
           

I am not sure why it doesn't work for multiple id's at once! If it helps the audio variable holds null values if I try multiple Ids, no errors.

Any help would be greately appreciated.

0 Answers
Related