예제 #1
0
        public async Task <IEnumerable <Track> > GetPlaylistTracks(Models.PlaylistRequest request)
        {
            var playlist = Playlists.First(t => t.Id == request.PlaylistId);

            LastTrackSet = await _spotifyWebApi.Get <Envelope <TrackShell> >(playlist.Tracks.Resource, Token);

            while (!string.IsNullOrWhiteSpace(LastTrackSet.Next?.ToString()))
            {
                LastTrackSet = await _spotifyWebApi.Get <Envelope <TrackShell> >(LastTrackSet.Next, Token);
            }

            return(Tracks);
        }
예제 #2
0
파일: GraphApi.cs 프로젝트: mamasha/tests
        string IGraphApi.Code2Token(string code)
        {
            var fb          = _config.ApiBaseUrl;
            var appId       = _config.AppId;
            var redirectUrl = _config.RedirectUrl;
            var appSecret   = _config.AppSecret;

            var url = $"{fb}/oauth/access_token?client_id={appId}&redirect_uri={redirectUrl}&client_secret={appSecret}&code={code}";

            var result = _web.Get(url, onFbError, new {
                access_token = "",
                token_type   = ""
            });

            return
                (result.access_token);
        }
        public async Task <IActionResult> Landing()
        {
            var queryStrings = HttpContext.Request.Query;

            if (queryStrings.TryGetValue("error", out var error))
            {
                _logger.Information($"error:{error}");
                return(BadRequest(error));
            }

            _playlistManager.Session = await _spotify.Authenticate(new AuthorizationResponse
            {
                Code  = queryStrings["code"],
                State = queryStrings["state"]
            }, _playlistManager.Hmac);

            _playlistManager.Me = await _spotify.Get <MeResponse>(SpotifyApi.Me, _playlistManager.Token);

            return(new OkObjectResult(_playlistManager.Me));
        }
        private List <BSAvailabilityDto> GetByWebApi(string url)
        {
            List <BSAvailabilityDto> response = null;
            double milliseconds = _maxWaitingMilliseconds;

            while (response == null && milliseconds >= MIN_WAITING_MILLISECONDS)
            {
                var watch = new Stopwatch();
                watch.Start();

                try { response = _webApi.Get <List <BSAvailabilityDto> >(url, milliseconds); } catch (Exception e) { }

                watch.Stop();
                milliseconds -= watch.ElapsedMilliseconds;
            }

            return(response ?? new List <BSAvailabilityDto>());
        }