Get steamID by user nickname
Asked Answered
C

6

11

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 :

You can use this to search the Dota2 API directly using the player_name option of GetMatchHistory You can then find their 32-bit ID in the list and then convert it to a 64-bit ID.

But now GetMatchHistory function does not have player_name parameter. Now it requires account_id.

So how the websites like http://dotabuff.com/search?q=Dendi get this info?

Chow answered 8/10, 2013 at 12:36 Comment(0)
H
22

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.

Hehre answered 7/5, 2014 at 15:33 Comment(1)
Small addendum: just like nicknames, custom URLs can change too. But since custom URLs are unique, you'll have to handle cases like "what if two players swapped their URLs?".Kelikeligot
B
2

This is JS answer, not PHP, but anyway

You can use this url address to get list of users from steamcommunity.com/search/ page

https://steamcommunity.com/search/SearchCommunityAjax?text=aaa&filter=users&sessionid=session&steamid_user=false&page=1

text means username, sessionid means sessionid from cookie files, which you can obtain by going to the site itself

Here is my crappy code for demo:

let axios = require('axios').default;

//create axios instance from which we will get to the search list
let instance = axios.create({ baseURL: 'https://steamcommunity.com' });

async function getSessionId() {

  let res = await axios.get('https://steamcommunity.com/');
  
  let [cookie] = res.headers['set-cookie'];
  
  instance.defaults.headers.Cookie = cookie;
  
  return cookie;

}

getSessionId().then(cookie => {

  let session = cookie.split(' ')[0].slice(10, -1);
  instance.get(`https://steamcommunity.com/search/SearchCommunityAjax?text=aaa&filter=users&sessionid=${session}&steamid_user=false&page=1`).then(res => {
  
    //i have regex
    let regex = /('<div>')/|/('<img>')/|/('<span>')/g
    
    //html also
    let arr = res.data.html.split(regex).join('').split('\t').join('').split('\n').join('').split('\r');

    arr = arr.filter(a => a !== '');
    
    arr = arr.filter(a => a.includes("searchPersonaName"));
    
    let result = [];

    arr.forEach(a => {
            
            let [link, name] = a.replace('<a class="searchPersonaName" href="','').replace('</a><br />','').split('">');

            let obj = {

                link,

                name

            };

            result.push(obj);
        
        });

        console.log(result); //logs out array of objects with links and usernames
  
  })
  
})
Boil answered 29/5, 2021 at 19:31 Comment(1)
This solution seems to be the most interesting one. It's weird that Steam does not provide a search apiChambless
W
1

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.

Wiretap answered 8/10, 2013 at 13:33 Comment(2)
I guess this is not possible anymore :DFoolish
I guess it is still possible.. But it more looks like SteamId::resolveVanityUrl('username'); but only IF the user has set the VanityUrl, whats most the case if you just see a name in the url.Kalvin
A
0

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);
}
};
Afroamerican answered 23/7, 2020 at 11:32 Comment(0)
J
-1

Simple way if you are not using an api

Go to your steam profile page Right Click -> Inspect Element -> Ctrl + F (Find) -> Type 'steamid' (Without quotes)

Thank me later :)

Jemison answered 12/9, 2021 at 14:54 Comment(0)
S
-9

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.
Seagraves answered 8/10, 2013 at 12:42 Comment(1)
Yes. This function requires steamids param. Which is set of steam IDs. Not nicknames.Chow

© 2022 - 2024 — McMap. All rights reserved.