문제

by this link you can get all matches from Dota 2 https://api.steampowered.com/IDOTA2Match_205790/GetMatchHistory/v001/?key=*******

but how to get matches of one single user by steamid?

도움이 되었습니까?

해결책

The first thing you need to do is convert the STEAM ID to a PROFILE ID. This can be accomplished using something like the Steam Condenser project, more simply this function from the Steam Condenser project. If you just use this function, you'll have to modify the exceptions thrown as the SteamCondenserException won't exist. If you have the unique player ID, I suggest using the entire Steam Condenser project and looking at this answer.

/**
* 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.");
        }
    }

Now that you have the 64bit ID, you can pass this to the API call you are already making. It will get passed to the account_id parameter.

In PHP, you will end up with something like this:

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

The three variables at the top of that snippet are for you to fill in with the number of matches you want returned, the Steam ID you are checking and the API KEY you are using. Your results will be in the $json_object and are for you to parse.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top