This code grabs all the steam IDs of a certain steam user’s friends. Then it splits them into arrays with 100 elements (each element containing a steam ID), because we can only pass GetPlayerSummaries
100 steam IDs at a time. But when I try to output some data, it only outputs data from 100 friends. I tried with a steam user that has 137 friends. I got two arrays:
- Array 0: contained 100 elements
- Array 1: contained 37 elements
$ids=array();
$url = "http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=mykey&steamid=".$other_steamid."&relationship=friend";
$data= file_get_contents( $url );
$json = json_decode( $data );
$ids=array();
/* just grab the IDs and add to array - correct format to access records??? */
foreach( $json->friendslist->friends as $obj ){
$ids[]=$obj->steamid;
}
$steamidcount = count($ids);
/* split the IDs into chunks of 100 */
$chunks=array_chunk( $ids, 100 );
/* send a request per chunk of 100 */
foreach( $chunks as $chunk ){
$url=sprintf('https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=mykey&steamids=%s',implode(',',$chunk));
$curl = curl_init( $url );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$res=curl_exec( $curl );
if ( $res ){
$data=json_decode($res,true);
for ($x = 0; $x <= count($data['response']['players']); $x++) {
$steamname = $data['response']['players'][$x]['personaname'];
$steamprofileurl = $data['response']['players'][$x]['profileurl'];
$friendimage = $data['response']['players'][$x]['avatar'];
$friendimageData = base64_encode(file_get_contents($friendimage));
echo '<img class="other_friendsteamimage" src="data:image/jpeg;base64,'.$friendimageData.'">';
echo "<a class='other_friendlabel' href='$steamprofileurl'>$steamname</a>";
echo "<br>";
}
}
curl_close($curl);
}
It only prints the first array. Any help?
question from:
https://stackoverflow.com/questions/65891677/only-the-first-array-of-steam-ids-is-printed 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…