Created
January 3, 2021 05:58
-
-
Save CanadianJeff/7ca3b6c6bf187662ecafcf5e01d4dddc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment