Answer the question
In order to leave comments, you need to log in
Why is the user's avatar not showing through the Steam API?
Good afternoon dear users of this portal. Tell me please. Below I have given the code, which should be the last 15 SteamIDs from my database, requesting their avatar via the Steam API, displaying them on the site in a grid. Everything would be fine, but only the avatars themselves are not displayed. Just white squares.
<div class="panel panel-default">
<?php
include("db_connect.php");
$usersData = [];
$steamIds = [];
$query = "SELECT steam_id FROM users_profiles ORDER BY `id` DESC limit 15";
$result = mysql_query($query)or die("MySQL Error");
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$usersData[$row['steam_id']] = $row;
$steamIds = $row['steam_id'];
}
}
$url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$steamauth['apikey']."&steamids=" . join(',', $steamIds);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
curl_close($ch);
$steamData = json_decode($result, true);
foreach($steamData['response']['players'] as &$player) {
$usersData[$player['steamid']]['steam_avatar'] = $player['avatarfull'];
$usersData[$player['steamid']]['steam_name'] = $player['personaname'];
}
$chunked = array_chunk($usersData, 3);
?>
<table class="table table-striped table-responsive table-bordered">
<tbody>
<?php foreach($chunked as &$chunked_row): ?>
<tr>
<?php foreach($chunked_row as &$chunked_cell): ?>
<td>
<center>
<img src="<?= htmlspecialchars($chunked_cell['steam_avatar']); ?>" width="50px" height="50px"/>
<?= htmlspecialchars($chunked_cell['steam_avatar']); ?>
</center>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question