Get steamID by user nickname

前端 未结 4 1713
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 14:02

Is it possible to get user\'s steamID by his nickname? I didn\'t find solution in steam API documentation. The only one thing that I found is an old post on http://dev.dota2.com

相关标签:
4条回答
  • 2021-02-04 14:24

    Using PHP and the Steam Condenser project, you can accomplish this.

    require_once('steam/steam-condenser.php');
    
    $playername = 'NAMEOFPLAYER';
    try
    {
        $id = SteamId::create($playername);
    } 
    catch (SteamCondenserException $s)
    {
        // Error occurred
    }
    
    echo $id->getSteamId;
    

    There are usage examples in the wiki for the project if you need more information.

    0 讨论(0)
  • 2021-02-04 14:26

    You can use

    GET http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/

    to get the SteamID from the custom URL of a Steam Profile. See http://wiki.teamfortress.com/wiki/WebAPI/ResolveVanityURL

    You can't get the steamID from someone's current nickname because nicknames can change and are not unique.

    0 讨论(0)
  • 2021-02-04 14:31

    Have you read over this from the Steam Web API?

    https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerSummaries_.28v0002.29

    It has an example of using a steam profile url to return the users Steam ID, also some other arguments to gather other information.

    If you read down a bit from there it states that "Returns the friend list of any Steam user

    Example URL: http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&steamid=76561197960435530&relationship=friend"

    • you can add the arguments for profile information to be returned such as the Steam ID providing the profile is public.
    0 讨论(0)
  • 2021-02-04 14:35

    Here is my solution for this problem:

    module.exports.getProfile = async (req, res) => {
    let response = { success: false, data: {}, error: {} }
    let { profileAddress } = req.body;
    if (profileAddress) {
        try {
            let steamId;
            let split = profileAddress.split('/');
            split = split.filter(arrayItem => arrayItem != '');
            if (split[split.length - 2] === 'profiles') {
                steamId = split[split.length - 1]
            } else {
                let vanityUrl = split[split.length - 1];
                let steamIdResponse = await axios.get(
                    `http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key=${process.env.steamApiKey}&vanityurl=${vanityUrl}`,
                );
                if (steamIdResponse.data.response.success === 1) {
                    steamId = steamIdResponse.data.response.steamid;
                } else {
                    response.error = steamIdResponse.data.response.message;
                }
            }
            let profileResponse = await axios.get(
                `http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=${process.env.steamApiKey}&steamids=${steamId}`,
            );
            if (profileResponse.data.response.players[0]) {
                response = {
                    success: true,
                    data: profileResponse.data.response.players[0],
                    error: null
                }
                res.status(200);
            } else {
                response.error = response.error ? response.error : "Failed to get Profile.";
                res.status(500);
            }
            res.send(response);
        } catch (error) {
            console.log(error)
            response.error = "Failed to get Profile."
            res.status(500).send(response);
        }
    } else {
        response.error = "Profile URL missing."
        res.status(500).send(response);
    }
    };
    
    0 讨论(0)
提交回复
热议问题