Hi
In below code i want to get token & what is the best option to save that token
- public class AccessToken
- {
- public string access_token { get; set; }
- public string token_type { get; set; }
- public long expires_in { get; set; }
- }
- private static async Task<string> GetToken()
- {
- string credentials = String.Format("{0}:{1}", clientId, clientSecret);
- using (var client = new HttpClient())
- {
- client.DefaultRequestHeaders.Accept.Clear();
- client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(credentials)));
- List<KeyValuePair<string, string>> requestData = new List<KeyValuePair<string, string>>();
- requestData.Add(new KeyValuePair<string, string>("grant_type", "client_credentials"));
- FormUrlEncodedContent requestBody = new FormUrlEncodedContent(requestData);
- var request = await client.PostAsync("https://accounts.spotify.com/api/token", requestBody);
- var response = await request.Content.ReadAsStringAsync();
- return JsonConvert.DeserializeObject<AccessToken>(response);
- }
- }
Thanks