Skip to content
MattRyder edited this page Jun 12, 2012 · 4 revisions

Here are some examples on how to use the SteamAPI to access data from the Valve servers.

## Creating a new SteamUser and echo'ing some basic profile data

//Call the SteamUser constructor with either the 17-digit Steam Community ID
//or their custom URL (i.e. robinwalker)
$api = new SteamAPI();
$user = $api->getUser($userID);

//Some basic profile data, their 64-bit SteamID, Online Status and banned status
echo "64-bit Steam ID: {$user->steamID64}", PHP_EOL;
echo "Online State: {$user->stateMessage}", PHP_EOL;
echo "VAC Banned Status: {$user->vacBanned}", PHP_EOL;

Output:

64-bit Steam ID: 76561197960435530
Online State: Last Online: 2 days ago
VAC Banned Status: 0

Accessing the SteamUser's Friends List

This example will output a list of 64-bit Steam IDs to the host window.

This assumes $user references a valid SteamUser object.

$user = new SteamUser($steamID);

if($user != NULL) {
    $fl = $user->getFriendsList(); //Pull the friends from the Steam API

    for($i = 0; $i < count($fl); $i++) {
        //echo each friends Steam ID
        echo "Friend Steam ID: {$fl[$i]->steamid}", PHP_EOL;
    }
}

Output (redacted for length):

Friend Steam ID: 76561197960265731
Friend Steam ID: 76561197960265738
Friend Steam ID: 76561197960265740
Friend Steam ID: 76561197960265747
...

Listing all Steam Games owned by a player

This example gathers all the Steam Games owned by a player, and lists it by App ID / Game Name / Hours On Record.

if($user != NULL) {
    //Grab the Games List, put it into $gl
    $gl = $user->getGamesList();
    
    printf("%-6s\t%-50s\t%-15s%s", "App ID", "Game Name", "Hours On Record", PHP_EOL); //Output a typical header

    for($i = 0; $i < count($gl); $i++) {
        printf("%-7s\t%-50s\t%-2.1f%s", //Formatting options for even listing in columns
                        $gl[$i]->appID, //App ID
                         $gl[$i]->name, //Game Name
                $gl[$i]->hoursOnRecord, //Hours on record
                               PHP_EOL); 
}
}

Output:

App ID	Game Name                                         	Hours On Record
48000  	LIMBO                                             	2.8
41070  	Serious Sam 3: BFE                                	6.9
113200 	The Binding of Isaac                              	2.7
22650  	Alien Breed 2: Assault                            	0.0
630    	Alien Swarm                                       	3.6
Clone this wiki locally