Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static string baseUrl = "https://snoonotes.com/auth/connect/token";
- static void Main(string[] args)
- {
- string username = "CMVModBot";
- string password = "";
- string clientId = "cLGbNpLYg9gt_Q";
- LoginTokenResult accessToken = GetLoginToken(username, password, clientId);
- if (accessToken.AccessToken != null)
- {
- Console.WriteLine(accessToken);
- }
- else
- {
- Console.WriteLine("Error Occurred:{0}, {1}", accessToken.Error, accessToken.ErrorDescription);
- }
- Console.ReadLine();
- }
- private static LoginTokenResult GetLoginToken(string username, string password, string clientId)
- {
- string content = $"grant_type=password&username={HttpUtility.UrlEncode(username)}&password={HttpUtility.UrlEncode(password)}&client_id={HttpUtility.UrlEncode(clientId)}";
- HttpClient client = new HttpClient();
- client.BaseAddress = new Uri(baseUrl);
- HttpResponseMessage response = client.PostAsync("Token", new StringContent(content, Encoding.UTF8, "application/x-www-form-urlencoded")).Result;
- string resultJSON = response.Content.ReadAsStringAsync().Result;
- LoginTokenResult result = JsonConvert.DeserializeObject<LoginTokenResult>(resultJSON);
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement