This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task<string> GetAccessToken() | |
{ | |
SpotifyToken token = new SpotifyToken(); | |
string postString = string.Format("grant_type=client_credentials"); | |
byte[] byteArray = Encoding.UTF8.GetBytes(postString); | |
string url = "https://accounts.spotify.com/api/token"; | |
WebRequest request = WebRequest.Create(url); | |
request.Method = "POST"; | |
request.Headers.Add("Authorization", "Basic {Encoded ClientId:ClientSecret}"); request.ContentType = "application/x-www-form-urlencoded"; | |
request.ContentLength = byteArray.Length; | |
using (Stream dataStream = request.GetRequestStream()) | |
{ | |
dataStream.Write(byteArray, 0, byteArray.Length); | |
using (WebResponse response = await request.GetResponseAsync()) | |
{ | |
using (Stream responseStream = response.GetResponseStream()) | |
{ | |
using (StreamReader reader = new StreamReader(responseStream)) | |
{ | |
string responseFromServer = reader.ReadToEnd(); | |
token = JsonConvert.DeserializeObject<<strong>SpotifyToken</strong>>(responseFromServer); | |
} | |
} | |
} | |
} | |
return token.access_token; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment