CS:GO 统计数据 Api [GetUserStatsForGame]

CS:GO Stats Api [GetUserStatsForGame]

我在使用 GetUserStatsForGame Api 时遇到了问题。我用了 http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=730&key=<<KEY>>&steamid=<<PROFILEID>>.

我怎样才能获得玩家统计数据?

我已经尝试过了,但它确实有效:/

 if(!$_SESSION['steamid'] == ""){
    include("settings.php");
    if (empty($_SESSION['steam_uptodate']) or $_SESSION['steam_uptodate'] == false or empty($_SESSION['steam_personaname'])) {

        @ $url = file_get_contents("http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=730&key=".$steamauth['apikey']."&steamids=".$_SESSION['steamid']);
        $content = json_decode($url, true);
        $_SESSION['total_kills'] = $content['playerstats']['stats']['total_kills'][0]['value'];
        $_SESSION['steam_steamid'] = $content['response']['players'][0]['steamid'];


}

    $csgoprofile['total_kills'] = $_SESSION['total_kills'];
}

请帮忙!

statsname/value 对的列表,因此 $content['playerstats']['stats']['total_kills'] 不会起作用。

total_kills 值的路径是 $content['playerstats']['stats'][0]['value'] 但你不能依赖 total_kills0.

你可以这样做:

$key = null;
foreach ($content['playerstats']['stats'] as $key => $stat) {
    if ($stat["name"] === "total_kills") {
        $key = $index;
    }
}

$total_kills = $content['playerstats']['stats'][$key]['value'];

如果您还想阅读其他统计数据,您可以这样做:

$stats = array();
foreach ($content['playerstats']['stats'] as $stat) {
    $stats[$stat["name"]] = $stat["value"];
}

$total_kills = $stats["total_kills"];
$total_deaths = $stats["total_deaths"];