Advertisement
SlothNGU

Quick Twitch Username Checker

Oct 7th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. //Include these two imports
  2. //using System.Net;
  3. //using System.Net.Http;
  4. //using System.Threading.Task; (might be Tasks)                  
  5. try
  6.         {
  7.             //Obviously u wanna configure this to work in ur program
  8.                         string Username = "aids";
  9.             using (HttpClientHandler handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate })
  10.             using (HttpClient client = new HttpClient(handler))
  11.             using (HttpRequestMessage request = new HttpRequestMessage() { Method = HttpMethod.Get, RequestUri = new Uri("https://api.twitch.tv/kraken/users/" + Username + "?client_id=xxxx") })
  12.             {
  13.                 //Only use this one if ur not comfortable with async shit all you have to do is make the function async
  14.                 //e.g. private async Task<bool> SuccMyToes() . <--- Change the bool to string or w/e if u want to
  15.                 //return a string or just change to to Task if u dont want to return anything :)
  16.                 //var response = client.SendAsync(request).GetAwaiter().GetResult();
  17.  
  18.                 var response = await client.SendAsync(request);
  19.                 if(response.StatusCode.ToString() == "422")
  20.                 {
  21.                     //Banned
  22.                     Console.WriteLine("Banned");
  23.                 }
  24.                 else if (response.StatusCode == HttpStatusCode.OK)
  25.                 {
  26.                     //In User
  27.                     Console.WriteLine("In use");
  28.                 }
  29.                 else
  30.                 {
  31.                     Console.WriteLine("Available");
  32.                     //Available
  33.                 }
  34.             }
  35.         }
  36.         catch (Exception ex) { Console.WriteLine(ex.Message); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement