9

是否可以通过昵称获取用户的 steamID?我没有在 Steam API 文档中找到解决方案。我发现的唯一一件事是http://dev.dota2.com上的一篇旧帖子:

您可以使用它直接使用 GetMatchHistory 的 player_name 选项搜索 Dota2 API,然后可以在列表中找到他们的 32 位 ID,然后将其转换为 64 位 ID。

但是现在GetMatchHistory函数没有player_name参数。现在它需要account_id.

那么像http://dotabuff.com/search?q=Dendi这样的网站是如何获得这些信息的呢?

4

6 回答 6

19

您可以使用

获取http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/

从 Steam 配置文件的自定义 URL 获取 SteamID。请参阅http://wiki.teamfortress.com/wiki/WebAPI/ResolveVanityURL

您无法从某人当前的昵称中获取 steamID,因为昵称可以更改并且不是唯一的。

于 2014-05-07T15:33:05.057 回答
1

使用 PHP 和Steam Condenser项目,您可以做到这一点。

require_once('steam/steam-condenser.php');

$playername = 'NAMEOFPLAYER';
try
{
    $id = SteamId::create($playername);
} 
catch (SteamCondenserException $s)
{
    // Error occurred
}

echo $id->getSteamId;

如果您需要更多信息,该项目的 wiki 中有使用示例

于 2013-10-08T13:33:18.130 回答
0

如果您不使用 api,那么简单的方法

转到您的 Steam 个人资料页面 右键单击​​ -> 检查元素 -> Ctrl + F(查找)-> 输入“steamid”(不带引号)

晚点再谢我 :)

于 2021-09-12T14:54:29.197 回答
0

这是 JS 答案,不是 PHP,但无论如何

您可以使用此 url 地址从steamcommunity.com/search/ 页面获取用户列表

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

text 表示用户名,sessionid 表示 cookie 文件中的 sessionid,您可以通过访问站点本身获取

这是我用于演示的糟糕代码:

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
  
  })
  
})

于 2021-05-29T19:31:53.713 回答
0

这是我对这个问题的解决方案:

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);
}
};
于 2020-07-23T11:32:38.247 回答
-9

您是否从 Steam Web API 中阅读过此内容?

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

它有一个使用 Steam 配置文件 url 返回用户 Steam ID 的示例,还有一些其他参数来收集其他信息。

如果您从那里仔细阅读,它会声明“返回任何 Steam 用户的朋友列表

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

  • 您可以为要返回的配置文件信息添加参数,例如提供公开配置文件的 Steam ID。
于 2013-10-08T12:42:34.817 回答