0

通过此链接,您可以从 Dota 2 https://api.steampowered.com/IDOTA2Match_205790/GetMatchHistory/v001/?key= * ** * ***

但是如何通过 steamid获取单个用户的匹配?

4

1 回答 1

1

您需要做的第一件事是将 STEAM ID 转换为 PROFILE ID。这可以使用类似Steam Condenser项目的东西来完成,更简单地说是 Steam Condenser 项目中的这个功能。如果你只是使用这个函数,你将不得不修改抛出的异常,因为它SteamCondenserException不存在。如果您有唯一的玩家 ID,我建议您使用整个 Steam Condenser 项目并查看此答案

/**
* 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 中,你最终会得到这样的结果:

$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;

该片段顶部的三个变量供您填写您想要返回的匹配数、您正在检查的 Steam ID 和您正在使用的 API KEY。您的结果将在$json_object并且供您解析。

于 2014-03-26T13:29:31.657 回答