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

FTP getting array of file details such as size using PHP

Using FTP and PHP to get an array of file details such as size and…

3 years ago

Creating Laravel form requests

Creating and using Laravel form requests to create cleaner code, separation and reusability for your…

3 years ago

Improving the default Laravel login and register views

Improving the default Laravel login and register views in such a simple manner but making…

3 years ago

Laravel validation for checking if value exists in the database

Laravel validation for checking if a field value exists in the database. The validation rule…

3 years ago