首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何获得用户的匹配?

如何获得用户的匹配?
EN

Stack Overflow用户
提问于 2014-03-26 12:37:54
回答 1查看 2.2K关注 0票数 0

通过这个链接,您可以从Dota 2 205790/GetMatchHistory/v 001/?key=*******获得所有匹配。

但是如何通过steamid获得一个用户的的匹配呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-26 13:29:31

您需要做的第一件事是将蒸汽ID转换为配置文件ID,这可以使用类似于蒸汽凝汽器项目的东西来实现,更简单的说,就是使用来自蒸汽凝汽器项目的这个函数。如果您只使用这个函数,您将不得不修改抛出的异常,因为SteamCondenserException将不存在。如果您有唯一的播放器ID,我建议使用整个蒸汽冷凝器项目,看看这个回答

代码语言:javascript
代码运行次数:0
运行
复制
/**
* Converts a SteamID as reported by game servers to a 64bit numeric
* SteamID as used by the Steam Community
*
* @param string $steamId The SteamID string as used on servers, like
* <var>STEAM_0:0:12345</var>
* @return string The converted 64bit numeric SteamID
* @throws SteamCondenserException if the SteamID doesn't have the correct
* format
*/
    public static function convertSteamIdToCommunityId($steamId) {
        if($steamId == 'STEAM_ID_LAN' || $steamId == 'BOT') {
            throw new SteamCondenserException("Cannot convert SteamID \"$steamId\" to a community ID.");
        }
        if (preg_match('/^STEAM_[0-1]:[0-1]:[0-9]+$/', $steamId)) {
            $steamId = explode(':', substr($steamId, 8));
            $steamId = $steamId[0] + $steamId[1] * 2 + 1197960265728;
            return '7656' . $steamId;
        } elseif (preg_match('/^\[U:[0-1]:[0-9]+\]$/', $steamId)) {
            $steamId = explode(':', substr($steamId, 3, strlen($steamId) - 1));
            $steamId = $steamId[0] + $steamId[1] + 1197960265727;
            return '7656' . $steamId;
        } else {
            throw new SteamCondenserException("SteamID \"$steamId\" doesn't have the correct format.");
        }
    }

既然您有了64位ID,就可以将其传递给您正在进行的API调用。它将被传递给account_id参数。

在PHP中,您将得到这样的结果:

代码语言:javascript
代码运行次数:0
运行
复制
$matches = 10;    // Return last 10 matches
$acct = convertSteamIdToCommunityId(STEAMIDYOUARECHECKING);
$APIKEY = <YOURKEYHERE>;

$steamurl = "https://api.steampowered.com/IDOTA2Match_570/GetMatchHistory/V001/?key=$APIKEY&account_id=$acct&Matches_Requested=$matches&format=json";
$json_object= file_get_contents($steamurl);
header('Content-Type: application/json');
echo $json_object;

这个片段顶部的三个变量是用来填充您想要返回的匹配数、您正在检查的蒸汽ID和您正在使用的API键。您的结果将在$json_object中,供您解析。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22661304

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档