Categories: Development

Steam api counting friends and games with PHP

Here are two handy functions to use in getting the games and friend count for a steam profile.

To count the games owned amount for a steam profile use:

function game_count($steamid)
{
    $data = json_decode(file_get_contents("https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=YOURAPIKEY&steamid=" . $steamid . "&include_played_free_games=0&include_appinfo=1"));
    $games_count = $data->response->game_count;
    return $games_count;
}

echo game_count('754686934578698');

To count the friends a steam profile has use:

function friend_count($steamid)
{
    $data = json_decode(file_get_contents("https://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=YOURAPIKEY&steamid=" . $steamid . "&relationship=friend"));
    $friends_count = count($data->friendslist->friends);
    return $friends_count;
}

echo friend_count('754678978080');

Dont forget to replace YOURAPIKEY with your steam apikey

Share

Recent Posts

Kennington reservoir drained drone images

A drained and empty Kennington reservoir images from a drone in early July 2024. The…

2 years ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

2 years ago

Early September spring shots

Some early September spring shots from a bushwalk, It is still too early for wildflowers.

3 years ago

Cloning an NVMe to SK Hynix Platinum P41 NVMe

I recently needed to clone over a smaller NVMe to a 2TB SK Hynix Platinum…

3 years ago

Using Laravel’s deleteDirectory to delete folders and their contents

If you ever needed a simple solution in Laravel to delete an entire directory and…

3 years ago

How to allow only 1 user to register in a Laravel application

How to enforce only one user to register or be registered in a Laravel web…

3 years ago