Beispiel #1
0
        private String SendAuthorizationCodeRequest(WebClient webClient, string url)
        {
            string GetResponse;

            try
            {
                GetResponse = webClient.DownloadString(url);
            }
            catch (WebException e)
            {
                HttpWebResponse webResp = (HttpWebResponse)e.Response;
                if (webResp.StatusCode == HttpStatusCode.Unauthorized)
                {
                    //Token expires or invalid, request new token
                    auth.GetRefreshAuthorizationCodeFlowAuthToken();

                    JObject jObject   = JObject.Parse(storage.AuthorizationCodeFlowAuthTokenResponse);
                    string  AuthToken = (string)jObject.SelectToken("access_token");
                    webClient.Headers.Set(HttpRequestHeader.Authorization, "Bearer " + AuthToken);

                    GetResponse = webClient.DownloadString(url);
                }
                else
                {
                    throw new WebException("Something went wrong with accessing spotify's api");
                }
            }

            if (String.IsNullOrEmpty(GetResponse))
            {
                throw new WebException("Something went wrong with accessing spotify's api. No data was returned.");
            }
            return(GetResponse);
        }
        public void StartEvent()
        {
            //    //Create tokens
            //    storage.p8Token = p8.GetToken();
            auth.GetRefreshAuthorizationCodeFlowAuthToken();
            auth.GetClientCredentialsFlowAuthToken();

            //    // Create a timer with a two second interval.
            //    //aTimer = new System.Timers.Timer(10000);

            //    // Hook up the Elapsed event for the timer.
            //    //aTimer.Elapsed += OnTimedEventAsync;
            //    //aTimer.AutoReset = true;
            //    //aTimer.Enabled = true;
            //    //Console.WriteLine("\n\n\n\nTHE START EVENT TIMER WAS STARTED\n\n\n\n");

            //    //refreshTimer = new System.Timers.Timer(1800000);
            //    ////To get token before 30 min.

            //    //// Hook up the Elapsed event for the timer.
            //    //refreshTimer.Elapsed += RefreshEventAsync;
            //    //refreshTimer.AutoReset = true;
            //    //refreshTimer.Enabled = true;
        }