Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private async Task<T> GetSpotifyType<T>(string token, string url) {
try
{
WebRequest request = WebRequest.Create(url);
request.Method = "GET";
request.Headers.Add("Authorization", "Bearer " + token);
request.ContentType = "application/json; charset=utf-8";
T type = default(T);
using (WebResponse response = await request.GetResponseAsync())
{
using (Stream dataStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(dataStream))
{
string responseFromServer = reader.ReadToEnd();
type = JsonConvert.DeserializeObject<T>(responseFromServer);
}
}
}
return type;
}
catch (Exception ex)
{
Logger.LogException("Error", ex); throw;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.