我遇到了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'];
}
请帮忙!
答案 0 :(得分:1)
stats
是name
/ 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"];