是否可以通过他的昵称获取用户的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等网站如何获取此信息?
答案 0 :(得分:13)
您可以使用
获取http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/
从Steam配置文件的自定义网址获取SteamID。见http://wiki.teamfortress.com/wiki/WebAPI/ResolveVanityURL
您无法从某人的当前昵称获取steamID,因为昵称可能会发生变化并且不是唯一的。
答案 1 :(得分: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中有usage examples。
答案 2 :(得分: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);
}
};
答案 3 :(得分: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
})
})
答案 4 :(得分:-6)
您是否从Steam Web API读过这篇文章?
https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerSummaries_.28v0002.29
它有一个使用steam profile url返回用户Steam ID的示例,还有一些其他参数来收集其他信息。
如果你从那里读了一下,它会说“返回任何Steam用户的朋友列表
”