[PHP] 使用 Steam Web API 获取游戏信息。
我以前出于好奇研究过蒸汽网络协议,所以我打算写出当时研究过的代码。
在 steam 端有一个获取游戏信息的 api,我只用了相当简单的代码描述就能获取我指定的游戏名称。
我想知道是否有可能根据这类信息创建某种网站(……)。
.
<?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'];
? >
在 appid 变量中输入游戏名称的编号。您可以通过查看游戏在 steam 上的商店页面的网址找到该编号。
这个 api 只允许你获取一个游戏名称(可能)的信息,所以很不方便。



![[PHP]DeepL 用于翻译的 API,同时保留 HTML 标记。](https://kuroko-labo.com/wp/wp-content/themes/kuroko3/images/noimage.png)