def get_user_id(name, timeout=10):
"""Resolves a username to a steamid, however is limited to ONLY vanity URL's. search_user_id is recommended
Args:
name (str): The name of the user to find the steamid of
timeout (int, optional): The amount of time before aiohttp raises a timeout error
Returns:
either None or a steamid (str) if a vanity url matching that name is found
"""
if name in userid_cache:
return userid_cache[name]
else:
_check_key_set()
with aiohttp.ClientSession() as session:
with aiohttp.Timeout(timeout):
resp = yield from session.get("http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key=" + STEAM_KEY + "&vanityurl=" + parse.quote(name))
data = yield from resp.json()
if "response" in data and "success" in data["response"] and data["response"]["success"] == 1:
id = data["response"]["steamid"]
if STEAM_CACHE:
userid_cache[name] = id
return id
return None
评论列表
文章目录