📜 ⬆️ ⬇️

A bit about Steam Web Api



Valve's digital distribution service Steam from Valve is becoming increasingly popular among players. As of January 2013, more than three thousand products are covered by Steam, which are subject to daily, weekly and weekend discounts, and the number of registered accounts has exceeded 60 million.

Currently, there is very little information about using Steam Api (or Steam Web Api) in Runet. In this topic, I will talk about how to get the information you need from the Steam community to integrate it into your sites, blogs, or just to get information about the user without logging in to Steam.

Let's start with the main thing. After some simple steps, I created a single php page that, on the request of a username , either SteamID or SteamcommunityID , displays a lot of detailed information about the Steam profile. Information there is much more than provide similar English-speaking services.
')
View the work page here . If you wish, you can significantly refine the service, for example, add the ability to determine which games are on the account of a particular user, and how much they cost (as steamcalculator once did) .

Who is interested in the source code of my page, the algorithm for determining the type of input data or the algorithm for searching the same xml parameters, you can write me here, or in the contact information on that page.

Open the hood Steam
Information about the user Steam can be obtained in several ways. The most popular ones are:
- use exactly Steam Web Api, which they offer us themselves (but the information provided there is, alas, not much)
- receive and process community data directly, in xml format.
- receive and process community data directly, in json format.

The first method is not very interesting to me, I used the two remaining ones at once.

XML
Getting user information is pretty simple. Just enter the request in the browser address bar in the form:
steamcommunity.com/profiles * SteamID * /? xml = 1
For example:
steamcommunity.com/profiles/76561198036370701/?xml=1
(by the way, if the user has CustomURL, then the link address will change from " ... / profiles / * SteamID * / ... " to " ... / id / * CustomURL * / ... ")

This page can be caught and processed using cURL or (which is easier for me) the functions simplexml_load_file (); , eg:
$slf = "http://steamcommunity.com/profiles/76561198036370701/?xml=1";
$url = simplexml_load_file($slf);

Now, to display, for example, the contents of the <steamID> ... </ steamID> tags, anywhere in your page, you can use the following code:
<?php echo $url->steamID;?>

Json
First you need apikey . You can register it here .

Get a summary of the user Steam can be on the link of the form:
api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key= * apikey * & steamids = * SteamID *
For example:
api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=38A3BEAE3EFA726E4438207D08CB0EC7&steamids=76561198036370701

You can receive and process this data using the file_get_contents command, and later converting everything into an array in this way:
$urljson = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=*apikey*&steamids=*steamid*");
$data = (array) json_decode($urljson)->response->players[0];

For example:
$urljson = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=38A3BEAE3EFA726E4438207D08CB0EC7&steamids=76561198036370701");
$data = (array) json_decode($urljson)->response->players[0];

And output, for example, the contents of the profileurl block with a line of code:
<?php echo $data['profileurl'];?>

Summarize
Methods of obtaining information about the user Steam are not limited to those that I cited. Those links that I received data are used only to obtain the total (general) information. Separately, you can get a list of user games, a list of friends, a list of groups, inventory and workshop items and much more.

On the basis of the data obtained, you can also make a service for generating banners, users, profiles for forums and blogs, by analogy with the steamprofile service.

Among the shortcomings of the service, it is possible to highlight that at the peak of loading Steam servers, to retrieve information about a user, the time for requesting data can vary from 0.1 to 12 seconds, and also often encounters error 503 (service unavailable), you have to send the request again. As a solution to the problem - do not send the request more than once every 10 seconds. If you have other ways to solve the problem, write.

Some links that will help in the development of Steam Web Api:
steamcommunity.com/dev?l=russian
partner.steamgames.com/documentation/webapi
developer.valvesoftware.com/wiki/Steam_Web_API
steamcommunityapi.googlecode.com/svn-history/r5/trunk

Source: https://habr.com/ru/post/172223/


All Articles