The main Api class.
Inheritance: BaseApi, ISpotifyWebApi
            public async Task <Data> GetResponse()
            {
                var webServer = new TcpListener(IPAddress.Any, 8000);

                webServer.Start();

                ConnectionService.OpenBrowser(this.ConnectUrl);

                var s = await webServer.AcceptSocketAsync();

                var bReceive = new byte[2048];
                var i        = s.Receive(bReceive, bReceive.Length, 0);

                // Convert Byte to String
                var sBuffer = Encoding.ASCII.GetString(bReceive);

                s.Shutdown(SocketShutdown.Both);
                webServer.Stop();

                var t = sBuffer.Split('?')[1].Split('&')[0].Split('=')[1];

                var token = AuthorizationCode.ProcessCallback(this.apiParameter, t, string.Empty);

                var api = new SpotifyWebApi.SpotifyWebApi(token);

                return(new Data(token, api));
            }
Esempio n. 2
0
        private PlaylistTrack getSongFromApi()
        {
            var param = new AuthParameters
            {
                Scopes       = Scope.All,
                ClientId     = SettingsLoader.SettingsContainer.Spotify_Client_Id,
                ClientSecret = SettingsLoader.SettingsContainer.Spotify_Client_Secret,
                RedirectUri  = "http://google.com",
                ShowDialog   = false, // Set to true to login each time.
            };

            var            token = ClientCredentials.GetToken(param);
            ISpotifyWebApi api   = new SpotifyWebApi.SpotifyWebApi(token);


            FullPlaylist playlist = api.Playlist.GetPlaylist(SpotifyUri.Make("spotify:user:1189618539:playlist:03gha5BWxoJ17xtn3FOvyl")).Result;

            return(playlist.Tracks.Items.OrderBy(x => Guid.NewGuid()).FirstOrDefault());
        }