PHP code example of pmzedx / steam-service

1. Go to this page and download the library: Download pmzedx/steam-service library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pmzedx / steam-service example snippets


use PmZedx\SteamService\SteamClient;

$steam = new SteamClient();

$steam = new SteamClient('your_api_key_here');

// Single profile
$data = $steam->users()->getProfiles('76561197960435530');
$player = $data['response']['players'][0];
echo $player['personaname']; // Display name
echo $player['avatarfull'];  // Avatar URL

// Multiple profiles (up to 100)
$data = $steam->users()->getProfiles([
    '76561197960435530',
    '76561197960287930',
]);

// Friend list
$data = $steam->users()->getFriends('76561197960435530');
foreach ($data['friendslist']['friends'] as $friend) {
    echo $friend['steamid'];
}

// All owned games
$data = $steam->player()->getOwnedGames('76561197960435530');
echo $data['response']['game_count'];

// With options
$data = $steam->player()->getOwnedGames(
    steamId: '76561197960435530',
    response']['games'] as $game) {
    echo $game['name'] . ': ' . $game['playtime_2weeks'] . ' minutes';
}

// Global achievement unlock rates for a game (no auth needed)
$data = $steam->userStats()->getGlobalAchievementPercentages(440);
foreach ($data['achievementpercentages']['achievements'] as $a) {
    echo $a['name'] . ': ' . $a['percent'] . '%';
}

// A player's achievement status in a game
$data = $steam->userStats()->getPlayerAchievements('76561197960435530', 440, language: 'en');
foreach ($data['playerstats']['achievements'] as $a) {
    echo $a['name'] . ': ' . ($a['achieved'] ? '✅' : '❌');
}

// A player's in-game stats
$data = $steam->userStats()->getPlayerStats('76561197960435530', 440);
foreach ($data['playerstats']['stats'] as $stat) {
    echo $stat['name'] . ': ' . $stat['value'];
}

$data = $steam->news()->getForGame(appId: 440, count: 5, maxLength: 300);
foreach ($data['appnews']['newsitems'] as $article) {
    echo $article['title'] . "\n" . $article['url'];
}

// Get a list of all supported API interfaces and methods
$data = $steam->webAPIUtil()->getSupportedAPIList();
foreach ($data['apilist']['interfaces'] as $interface) {
    echo $interface['name'] . "\n";
}

// Get server info (current time, etc.)
$data = $steam->webAPIUtil()->getServerInfo();
echo $data['servertime'];

// Get SteamIDs associated with a given IP address
$data = $steam->gameServer()->getServerSteamIDsByIP('192.168.1.100');

// Get the current status of all game servers
$data = $steam->gameServer()->getGameServersStatus();

// Get definitions of all leaderboards for a game
$data = $steam->leaderboards()->getLeaderboardDefinitions(440);

// Get entries from a specific leaderboard
$data = $steam->leaderboards()->getLeaderboardEntries(
    appId: 440,
    leaderboardId: 12345,
    start: 1,
    end: 10,
    steamId: '76561197960435530' // optional, to filter for a specific user
);

// Get a list of lobbies for a game
$data = $steam->matchmaking()->getLobbyList(
    appId: 440,
    max: 10,
    filter: 'gamedir:tf' // optional filter
);

// Get data for a specific lobby
$data = $steam->matchmaking()->getLobbyData('123456789012345678');

// Get details for one or more Workshop files
$data = $steam->publishedFile()->getDetails([123456, 789012]);

// Get subscriptions for a specific user
$data = $steam->publishedFile()->getSubscriptions('76561197960435530');

// Authenticate a user using a Steam authentication ticket
$data = $steam->userAuth()->authenticateUser(
    steamId: '76561197960435530',
    ticket: 'your_ticket_here',
    sessionKey: 'optional_session_key', // base64 encoded
    encrypted: 'optional_encrypted_data'
);

use PmZedx\SteamService\Exceptions\SteamApiException;

try {
    $data = $steam->users()->getProfiles('76561197960435530');
} catch (SteamApiException $e) {
    echo 'Steam API error: ' . $e->getMessage();
}