public static SpotifyUser QueryServiceForCurrentUser(AuthenticationObject authObj) { SpotifyUser user = new SpotifyUser(); using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authObj.access_token); var response = client.GetAsync($"https://api.spotify.com/v1/me").Result; var responseContent = response.Content; var responseString = response.Content.ReadAsStringAsync().Result; user = JsonConvert.DeserializeObject <SpotifyUser>(responseString); } return(user); }
private static SpotifyPlaylist CreatePlaylist(PlaylistRequest request, AuthenticationObject authObj, SpotifyUser user) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authObj.access_token); var httpRequest = new HttpRequestMessage(HttpMethod.Post, $"https://api.spotify.com/v1/users/{user.id}/playlists") { Content = new StringContent($"{{\"name\":\"{request.Name}\"}}", Encoding.UTF8, "application/json") }; httpRequest.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = client.SendAsync(httpRequest).Result; var responseContent = response.Content.ReadAsStringAsync().Result; return(JsonConvert.DeserializeObject <SpotifyPlaylist>(responseContent)); } }