Blazor & WASM in combination to get statistics from Spotify API for performing the song analysis. With separate microservices for auth, Spotify, user data tracking, and application, connected through gRPC with Polly.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

StatsService.cs 971B

1234567891011121314151617181920212223242526272829303132
  1. using GrpcShared.DTO;
  2. using GrpcShared.DTO.Track;
  3. using GrpcShared.Interfaces;
  4. using Microsoft.Net.Http.Headers;
  5. using Newtonsoft.Json;
  6. namespace SpotifyService.Services
  7. {
  8. public class StatsService : IStatsService
  9. {
  10. private readonly IHttpClientFactory _httpClientFactory;
  11. public StatsService(IHttpClientFactory httpClientFactory)
  12. {
  13. _httpClientFactory = httpClientFactory;
  14. }
  15. public async Task<TrackResponse> GetCurrentlyPlayingTrack(TokenMessage token)
  16. {
  17. var client = _httpClientFactory.CreateClient("HttpClient");
  18. client.DefaultRequestHeaders.Add(HeaderNames.Authorization, "Bearer " + token.Token);
  19. var searchResult = await client.GetAsync($"me/player/currently-playing");
  20. var responses = JsonConvert.DeserializeObject<TrackResponse>(await searchResult.Content.ReadAsStringAsync())!;
  21. return responses;
  22. }
  23. }
  24. }