Skip to content

Instantly share code, notes, and snippets.

@gabyfle
Created March 23, 2019 12:33
Show Gist options
  • Save gabyfle/1e13776a2e7722d8b8533807fbf74dec to your computer and use it in GitHub Desktop.
Save gabyfle/1e13776a2e7722d8b8533807fbf74dec to your computer and use it in GitHub Desktop.
Gets game count and total hours for a specific Steam account.
<?php
/**
* Gets steam stats from Steam's API
* @author Gabriel Santamaria <gaby.santamaria@outlook.fr>
*/
$steam_api = "APIKEYLOL";
$steam_id = "76561198127516196";
$jsonurl = "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=" . $steam_api . "&steamid=" . $steam_id . "&format=json";
$json = file_get_contents($jsonurl);
$decoded = json_decode($json, true);
$totalGames = $decoded["response"]["game_count"];
$totalHours = 0;
/**
* Sum of all hours per game
*/
foreach ($decoded["response"]["games"] as $key => $value) {
$totalHours = $totalHours + $value["playtime_forever"];
}
echo $totalGames . ' owned games.';
echo '<br>';
echo $totalHours / 60 . ' hours played.';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment