The problem you have is that steam groups can be quite large. Iterating over all of the data on each page visit isn't going to work at all. If you're building a system that HAS to keep track of all players in the group, then you would need to build an API of your own that communicates with the valve API's and creates a cache of the users.
You don't have to send a request per-user, but you are limited to 100 per request to the API.
Here is how you would get the first 100 users in a group. Any further requires that multiple requests be made with a maximum player limit of 100.
Fill in the API Key and what group you're looking at. DONT SHARE YOUR API KEY ON THE FORUMS.
PHP Code:
<?php
//Turn off errors in production since they can potentially reveal request information.
//error_reporting(0);
//Uncomment before public
/* A Generic GET request with cURL
* String $cURL - URL to request
* return array
*/
function ValveGET_cURL($cURL) {
$request = curl_init( trim($cURL) );
curl_setopt( $request, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $request, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt( $request, CURLOPT_MAXREDIRS, 3);
curl_setopt( $request, CURLOPT_AUTOREFERER, TRUE);
curl_setopt( $request, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt( $request, CURLOPT_TIMEOUT, 10);
$result = curl_exec( $request );
$info = curl_getinfo( $request );
$error = curl_errno( $request );
curl_close( $request );
return array('data' => $result, 'info' => $info, 'error' => $error);
}
$groupid = "steamuniverse";
$API_KEY = "FILL THIS";
$group_URL = 'http://steamcommunity.com/groups/' . $groupid . '/memberslistxml/?xml=1';
$return_array = ValveGET_cURL($group_URL);
$return_data = $return_array['data'];
$return_info = $return_array['info'];
$return_error = $return_array['error'];
//handle cURL errors
if($return_error !== 0) {
error_log("Steam Group Thingy returned with cURL Error: " . $return_error, 0);
exit;
}
$http_code = $return_info['http_code'];
if($http_code !== 200) {
//Server is probably down, give a generic message if you want
echo "Steam API is down";
exit;
} else {
//Request was successfull
$group_object = simplexml_load_string($return_data);
$group_object_members = $group_object->members->steamID64;
$steamids = array();
foreach($group_object_members as $user) {
$string = (string)$user;
if(ctype_digit($string)) {
$steamids[] = $string;
}
}
//Turn the first 100 or less into a string for the request.
$idcount = count($steamids);
$x = ($idcount < 100) ? $idcount : 100;
$giantlistofusers = "";
for($i = 0; $i < $x; $i++) {
$giantlistofusers .= $steamids[$i];
if($i <= $x) {
$giantlistofusers .= ',';
}
}
$request_URL2 = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $API_KEY . '&steamids=' . urlencode($giantlistofusers) . '&format=xml';
$player_return = ValveGET_cURL($request_URL2 );
$player_data = $player_return['data'];
$player_info = $player_return['info'];
$player_error = $player_return['error'];
//handle cURL errors
if($player_error !== 0) {
error_log("Steam Group Thingy returned with cURL Error: " . $player_error, 0);
exit;
}
$http_code2 = $player_info['http_code'];
if($http_code2 !== 200) {
//Server is probably down, give a generic message if you want
echo "Steam API is down";
exit;
} else {
$player_object = simplexml_load_string($player_data);
var_dump($player_object->players);
}
}
?>
In order to make it complete you would have to enumerate how many users per memberslist page, send a request for each 100, then get the next memberlist page and keep going until all steamID64 ID's have been accounted for.
Again, this isn't necessary if you look at specific users rather than trying to get an entire group.