title: im getting a error 401 unauthorized using the spotify api in c# wpf
body: <p>Im getting this Error. System.Net.WebException: 'The remote server returned an error: (401) Unauthorized.' Code is provided below.</p>
  
  <p>When i take out the method "PrintUsefulData(api)", everything seems to work fine
  that method has a http client webrequest. Im trying to request the following <a href="https://api.spotify.com/v1/albums" rel="nofollow noreferrer">https://api.spotify.com/v1/albums</a>.</p>
  
  <pre><code>    static void Main(string[] args)
      {
          _clientId = string.IsNullOrEmpty(_clientId)
              ? Environment.GetEnvironmentVariable("my_clientId")//my id
              : _clientId;
  
          _secretId = string.IsNullOrEmpty(_secretId)
              ? Environment.GetEnvironmentVariable("my_secretId") // my id
              : _secretId;
  
  
          AuthorizationCodeAuth auth =
              new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:5002", "http://localhost:5002", Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative);
          auth.AuthReceived += AuthOnAuthReceived;
          auth.Start();
          auth.OpenBrowser();
  
  
          Console.ReadLine();
          auth.Stop(0);
  
      }
  
      private static async void AuthOnAuthReceived(object sender, 
      AuthorizationCode payload)
      {
          AuthorizationCodeAuth auth = (AuthorizationCodeAuth)sender;
          auth.Stop();
  
          Token token = await auth.ExchangeCode(payload.Code);
          SpotifyWebAPI api = new SpotifyWebAPI
          {
              AccessToken = token.AccessToken,
              TokenType = token.TokenType
          };
          PrintUsefulData(api);
      }
  
      private static async void PrintUsefulData(SpotifyWebAPI api)
      {
  
          RestClient rClient = new RestClient();
          rClient.endPoint = "https://api.spotify.com/v1/albums";
          string strResponse = string.Empty;
          strResponse = rClient.getRequest();
  
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>public enum HttpVerb
  {
      GET,
      POST,
      PUT,
      DELETE
  }
  
  class RestClient
  {
      public string endPoint { get; set; }
      public HttpVerb httpMethod { get; set; }
  
      public RestClient()
      {
          endPoint = string.Empty;
          httpMethod = HttpVerb.GET;
      }
  
      public string getRequest()
      {
          string strResponseVal = string.Empty;
  
          HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endPoint);
          request.Method = httpMethod.ToString();
  
          using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
          {
              if (response.StatusCode != HttpStatusCode.OK)
              {
                  throw new ApplicationException("error code: " + response.StatusCode);
              }
              using (Stream responseStream = response.GetResponseStream())
              {
                  if (responseStream != null)
                  {
                      using (StreamReader reader = new StreamReader(responseStream))
                      {
                          strResponseVal = reader.ReadToEnd();
                      }
                  }
              }
          }
          return strResponseVal;
      }
  }
  </code></pre>
  
  <p>}</p>