Advertisement
Guest User

Recursion Steam

a guest
May 31st, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?php
  2. class SteamFriendFinder
  3. {
  4.     private $players = array();
  5.     private $handle = null;
  6.     private $apiKey = "XXXXXXXXXXX";
  7.    
  8.     public function __construct()
  9.     {
  10.         $this->handle = fopen("steam.txt","a+");   
  11.     }
  12.    
  13.     public function getFriends($id,$level = 0)
  14.     {
  15.         $f = @file_get_contents("http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=".$this->apiKey."&steamid=".$id."&relationship=friend");
  16.        
  17.         if ($f){
  18.         $arr = json_decode($f);
  19.        
  20.         foreach($arr->friendslist->friends as $friend)
  21.         {
  22.             $str = null;
  23.            
  24.             for ($i=0;$i<$level;$i++)
  25.             {
  26.             $str .= '.';   
  27.             }
  28.            
  29.             if (!isset($this->players[(string)$friend->steamid]))
  30.             {
  31.                 $str .= $this->getUsernameById((string)$friend->steamid);
  32.                
  33.             echo $str."\n";
  34.             fwrite($this->handle,$str."\r\n");
  35.            
  36.             $this->players[(string)$friend->steamid] = $friend;
  37.             $this->getFriends((string)$friend->steamid,$level+1);
  38.            
  39.             }
  40.            
  41.         }
  42.         }
  43.     }
  44.    
  45.     public function getUsernameById($id)
  46.     {
  47.         $f = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$this->apiKey."&steamids=".$id);
  48.        
  49.         $arr = json_decode($f);
  50.         return $arr->response->players[0]->personaname;
  51.            
  52.     }
  53. }
  54.  
  55. $sff = new SteamFriendFinder();
  56. $sff->getFriends("76561198027123396");
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement