public async Task <string> GetSteamIdFromSteamProfileUsername(string username) { try { using (var httpClient = new HttpClient()) { string url = string.Format(STEAM_RESOLVE_VANITY_URL, Properties.Resources.steam_api_key, username); HttpResponseMessage result = await httpClient.GetAsync(url); if (result.StatusCode == HttpStatusCode.OK) { string json = await result.Content.ReadAsStringAsync(); VanityUrlResponse obj = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <VanityUrlResponse>(json)); if (obj?.Response != null && obj.Response.Success == 1) { return(obj.Response.SteamId); } } } } catch (Exception e) { Logger.Instance.Log(e); } return(string.Empty); }
// vanityUrl can just be the custom name - it does not have to be the entire url. public async Task <long?> GetUserIdAsync(string vanityUrl) { using (HttpResponseMessage response = await RequestAsync(vanityUrl)) { if (response.IsSuccessStatusCode) { var json = await response.Content.ReadAsStringAsync(); var resp = VanityUrlResponse.FromJson(json); return(resp.Success ? resp.SteamUserId : null); } } return(null); }