From f7f527b0b02dc100338a8387d8f951a5045f5532 Mon Sep 17 00:00:00 2001 From: Demis Bellot Date: Mon, 11 Sep 2023 12:26:48 +0800 Subject: [PATCH] Update SpotifyOAuth2Provider.cs --- MusicTypeChat/SpotifyOAuth2Provider.cs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/MusicTypeChat/SpotifyOAuth2Provider.cs b/MusicTypeChat/SpotifyOAuth2Provider.cs index ccdc0aa..fa50524 100644 --- a/MusicTypeChat/SpotifyOAuth2Provider.cs +++ b/MusicTypeChat/SpotifyOAuth2Provider.cs @@ -82,21 +82,19 @@ protected override async Task> CreateAuthInfoAsync(st var json = await DefaultUserProfileUrl .GetJsonFromUrlAsync(request => { request.Headers.Add("Authorization", "Bearer " + accessToken); }, token: token).ConfigAwait(); - var obj = JsonObject.Parse(json); + var obj = (Dictionary) JSON.parse(json); obj.Add("name", obj["display_name"]); obj.MoveKey("id", "user_id"); - if (obj.ContainsKey("images") && !string.IsNullOrEmpty(obj["images"])) + if (obj.TryGetValue("images", out var oImages) && oImages is List { Count: > 0 } images) { - if (JsonNode.Parse(obj["images"]) is JsonArray { Count: > 0 } imagesArray) + var firstImage = (Dictionary)images[0]; + if (firstImage.TryGetValue("url", out var oUrl) && oUrl is string url) { - var firstImage = imagesArray[0]?.AsObject(); - if (firstImage != null && ((IDictionary)firstImage).TryGetValue("url", out var value)) - { - obj[AuthMetadataProvider.ProfileUrlKey] = value?.ToString(); - } + obj[AuthMetadataProvider.ProfileUrlKey] = url; } } - return obj; + var objStr = obj.ToStringDictionary(); + return objStr; } }