【问题标题】:CS:GO Stats Api [GetUserStatsForGame]CS:GO 统计 API [GetUserStatsForGame]
【发布时间】:2015-08-25 12:44:32
【问题描述】:

我遇到了 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'];
}

请帮忙!

【问题讨论】:

  • 输出的 JSON 是什么样的?快速猜测一下,$content['playerstats'][.. 应该是 $content['response']['playerstats'][.. 吗?
  • { "playerstats": { "steamID": "17343684926432", "gameName": "ValveTestApp260", "stats": [ { "name": "total_kills", "value": 41269 }, { "name": "total_deaths", "value": 41720 },

标签: php api steam


【解决方案1】:

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

total_kills 值的路径是 $content['playerstats']['stats'][0]['value'],但您不能依赖 total_kills 位于 0

你可以这样做:

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

【讨论】:

  • 非常感谢,但我没有得到任何输出。有什么想法吗?
  • 你期待什么输出?确保您已打开错误报告 (stackoverflow.com/questions/845021/…),以便您可以看到任何错误消息。
  • 这不是错误(顺便说一句,我把它打开了)。我期望这样的输出:<?php echo "" . $total_kills . "</br>"; ?>
  • 好的,我做到了。非常感谢(^_^)
猜你喜欢
  • 1970-01-01
  • 2015-03-01
  • 2016-02-22
  • 2014-11-16
  • 2011-04-12
  • 1970-01-01
  • 2021-12-05
  • 2015-01-23
相关资源
最近更新 更多