TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ramco Ramco
439
3.4k
544.8k
Token in JsonFormat
Feb 7 2021 7:40 AM
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
Reply
Answers (
4
)
How to insert multiple data in a table?
Create a QR code with multiple textboxes