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
string , string>> requestData = new Liststring, 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
(response); - }
- }
Thanks

Rijwan AnsariRank #82 · 24.2K reputationPosted Feb 7, 2021, 8:55 AM EST
Jaimin ShethiyaRank #177 · 13.7K reputationPosted Feb 10, 2021, 4:38 AM EST
if you want to store the token then you have to used in memory cache in your application and used that in your application and used.
if that token details are used in front-end side then you have to store that data in localstorage and used in front side.
Thanks.
Sachin SinghRank #66 · 26.2K reputationPosted Feb 7, 2021, 5:29 AM EST
Ramco RamcoRank #462 · 5.4K reputationPosted Feb 7, 2021, 8:14 AM EST