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
Jaimin ShethiyaPosted Feb 10, 2021, 9:38 AM
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.
Rijwan AnsariPosted Feb 7, 2021, 1:55 PM
Ramco RamcoPosted Feb 7, 2021, 1:14 PM
Sachin SinghPosted Feb 7, 2021, 10:29 AM