SmItH197 / SteamAuthentication

A simple PHP Authentication that enables steam users to log into their steam account to access content!
MIT License
446 stars 147 forks source link

How to show profile information with steamid ? #243

Closed ghost closed 5 years ago

ghost commented 5 years ago

Hi, is it prossible to show profile information (ex: logo) with only the steamid ? (Ex: admin user put is steamid on the admin page and on home page, everyone see is logo)

bman46 commented 5 years ago

Yes, I don’t believe that this library will do it, but a call to the JSON API using the url: http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXXXXXXXXXXX&steamids=76561197960435530 will return json data and the avatar image URLs. To use this just replace ur steam API key where the X’s are and the 76... area with the steam ID. Here is a tutorial on JSON in php: https://www.tutorialrepublic.com/php-tutorial/php-json-parsing.php

bman46 commented 5 years ago

Once you have the URL, I don’t believe that the url changes so you could probably store it in a database or just manually put in the url into a image area. Not 100% sure about that though, I haven’t used this in awhile.

bman46 commented 5 years ago

Correction, just checked and it does change if they change there avatar photo.

AlenasSenpai commented 5 years ago

If the aim is to show who the admin is by showing their avatar and username(with a link to their profile) you would need to use an insert to add users to a database on login then query the row id for that user, I have done this myself, but I’m currently at work, so I’ll jump on later with more info on the how unless someone beats me to it :)

ghost commented 5 years ago

Ok, thanks for your answer. I found the solution, if someone want:

$SteamAPIKey = "3503F6426195374A890F3467D028717C";
$stamidtest = "76561198179720810";

$url = file_get_contents("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$SteamAPIKey."&steamids=".$stamidtest);
$content = json_decode($url, true);
$steamavatar = $content['response']['players'][0]['avatarfull'];

?>

<img src="<?=$steamavatar?>">
ghost commented 5 years ago

And how can i check if steamid64 is valid, else echo wrong steamid ? Because if steam id 64 is wrong it say: Notice: Undefined offset: 0, and for my user i only want something like that: 'SteamID 64 isn't valid !'

bman46 commented 5 years ago

If it’s incorrect it will return a http error code More on that here: https://partner.steamgames.com/doc/webapi_overview/responses

ghost commented 5 years ago

Yes but how can i make a confition If(steam return error) { echo "wrong steam id"; } else { ... }

bman46 commented 5 years ago

https://gist.github.com/james2doyle/33794328675a6c88edd6

ghost commented 5 years ago

And how can i call function json_response in my "script" ? (Sorry i'm starter)

bman46 commented 5 years ago

https://github.com/bman46/Steam-Avatar Here's the code for that. I made it so then if the image doesn't exist then it returns the default ? icon for steam.

bman46 commented 5 years ago

Make sure to cache them if you are working on a production site as it will make a API request every time the image is loaded so you will quickly run out of API calls.

ghost commented 5 years ago

Tanks a lot !!!!

bman46 commented 5 years ago

No problem