0

I want to get the image from players steam profiles, and use them on my site, so when they change image/photo it will change at me.

This is just one that will load at a time, and when loading it shall go get the newest url. You can use this url for testing, what i need is getting the image url in the div with this class: and copy only the image url.

Link to test steamprofile: http://steamcommunity.com/profiles/76561197991341238

Code I have tried:

foreach($html->find('div[class=avatarFull]') as $div) 
{     
    foreach($div->find('img') as $img)
    {
        echo "<img src='" . $img->src . "'/>";          
    }
}
Tim Post
  • 33,371
  • 15
  • 110
  • 174
Lasse Andersen
  • 85
  • 1
  • 2
  • 9

3 Answers3

3

Use steam web api (documentation), GetPlayerSummaries method it works without html scrapping

SkyRaptor
  • 58
  • 1
  • 5
kirugan
  • 2,514
  • 2
  • 22
  • 41
  • It it long time since i coded last, so i could get an sample code that is why i gave a link :) Cuz i'm learning allover one more time :) Thx – Lasse Andersen Jan 06 '13 at 16:51
0

Using koraktor's Steam Condenser, you can easily pull this information and use it.

require_once('steam/db.php');
$_STEAMAPI = "YOURAPIKEYHERE";   // You get this from http://steamcommunity.com/dev/apikey
$playersStr = "";                // This is a comma separated list of profile IDs
                                 // if you don't have those, Steam Condenser has functions to acquire it
$players = array();              // For this example, I'm building an array of players assuming you'll have multiple players returned. 
                                 // You are free to skip this if you are only pulling one back
$url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$_STEAMAPI&steamids=$playersStr";
$json_object= file_get_contents($url);
$json_decoded = json_decode($json_object);

foreach ($json_decoded->response->players as $player)
{
    $players[$player->steamid]['personaname'] = $player->personaname;     // In game name
    $players[$player->steamid]['profileurl'] = $player->profileurl;       // URL to their Steam Community Page
    $players[$player->steamid]['avatar'] = $player->avatar;               // Small Avatar Icon URL
    $players[$player->steamid]['avatarmedium'] = $player->avatarmedium;   // Thumbnail avatar URL
    $players[$player->steamid]['avatarfull'] = $player->avatarfull;       // Full sized Avatar URL
}    

If you don't have a player's profile ID but do have the Steam ID, you can get the profile ID like this:

$profile_id = SteamId::convertSteamIdToCommunityId($steam_id);
Andy
  • 49,085
  • 60
  • 166
  • 233
-2

I think RegEx ( preg_match ) is simpler way to do it

$html = file_get_contents("http://steamcommunity.com/profiles/76561197991341238");
preg_match('/<div class="avatarFull"><img src="(.*)" \/><\/div>/i', $html, $profile_picture); // $profile_picture[1]; is the url itself

and if you're trying to grab multiple pictures from the same url then replace preg_match with preg_match_all and run a loop on $profile_picture[1]

Osa
  • 1,922
  • 7
  • 30
  • 51
  • The $html and $profilepicture where do i get thoose values from, like i commented "Kirugan" I'm a big noob at the time.. :) – Lasse Andersen Jan 06 '13 at 17:00
  • $html is the page content, they're grabbed using curl ,`file_get_contents` or any url parser... $profile_picture is the result, it's not supposed to be an active variable, so when you eco the url just use echo $profile_picture[1]; .. answer updated – Osa Jan 06 '13 at 17:02
  • Thx for fast reply and easy use. Works and many thx for the explaining :) – Lasse Andersen Jan 06 '13 at 17:10
  • @user1778037 If the site changes their HTML for the profile page this code will likely break and then so will the page you use it on. It's not at all robust. If you used the API as 'kirugan' suggested it would be resilient against any site layout changes. – kittycat Jan 06 '13 at 17:53