Exemplo n.º 1
0
        public async UniTaskVoid FromAuthorizationCode(string authorizationCode)
        {
            try
            {
                string clientId     = SpotifyConfiguration.ClientConfiguration.ClientID;
                string clientSecret = SpotifyConfiguration.ClientConfiguration.ClientSecret;
                Uri    redirectUri  = SpotifyConfiguration.ServerConfiguration.Uri;

                var response = await new OAuthClient().RequestToken(
                    new AuthorizationCodeTokenRequest(clientId, clientSecret, authorizationCode, redirectUri)
                    );

                var config = SpotifyClientConfig
                             .CreateDefault()
                             .WithAuthenticator(new AuthorizationCodeAuthenticator(clientId, clientSecret, response));
                Value = new SpotifyAPI.Web.SpotifyClient(config);

                Debug.Log("Login and client configuration successful.");

                OnAuthenticationCompleted.Raise();
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
Exemplo n.º 2
0
        public async Task <List <FullTrack> > GetAlbumTracks(string albumId)
        {
            albumId = albumId.Replace("spotify:album:", "").Trim();

            var token   = authClient.Authorize();
            var spotify = new SpotifyAPI.Web.SpotifyClient(token);

            var tmpTracks = await spotify.Albums.GetTracks(albumId, new AlbumTracksRequest
            {
                Limit = 50
            });

            var trackIds = tmpTracks.Items.Select(r => r.Id).ToList();

            var tracks = new List <FullTrack>();

            foreach (var trackId in trackIds)
            {
                var track = await spotify.Tracks.Get(trackId);

                tracks.Add(track);
            }

            return(tracks.OrderBy(r => r.TrackNumber).ToList());
        }
Exemplo n.º 3
0
        public SpotifyClient( )
        {
            Log.Information("Connecting to Spotify...");

            SpotifyClientConfig spotifyConfig = SpotifyClientConfig.CreateDefault( )
                                                .WithAuthenticator(
                new ClientCredentialsAuthenticator(
                    Config.SotifyClientID,
                    Config.SotifyClientSecret));

            spotifyClient = new SpotifyAPI.Web.SpotifyClient(spotifyConfig);

            Log.Information("Connection to Spotify successful");
        }