[PHP]Retrieving game information with the Steam Web API
I was curious about the steam web api before, so I thought I’d write down the code I found.
There is an api for obtaining game information published on the steam side, and I was able to obtain the title of the game I specified with a fairly simple code entry.
I wonder if it is possible to make a website based on this kind of information (…x
. <?php // Put the game title number here $appid = 0; // Get basic game information $appUrl = "https://store.steampowered.com/api/appdetails?appids={$appid}&cc=JP&l=japanese"; // Initialize cURL session $ch = curl_init(); // set cURL options curl_setopt($ch, CURLOPT_URL, $appUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Execute the request $response = curl_exec($ch); // close cURL session curl_close($ch); // Convert json data to an associative array $appData = json_decode($response, true); // if no data, exit if (! $appData || ! $appData[$appid]['success']) { die("Failed to retrieve game information. "); } // Assign game information to a variable $info = $appData[$appid]['data']; // display game title echo $info['name']; ? >
Put the game title number in the appid variable. You can find the number by looking at the url of the game’s store page on steam.
This api can only retrieve information for one game title (probably), so that is inconvenient.