[PHP]Steam Web API로 게임 정보 얻기
예전에 호기심에 steam web api에 대해 알아본 적이 있는데, 그때 알아본 코드를 작성해 보려고 합니다.
steam 측에서 공개되어 있는 게임 정보를 가져오는 api가 있는데, 꽤 간단한 코드 작성으로 지정한 게임 타이틀 등을 가져올 수 있었습니다.
이런 정보를 바탕으로 웹사이트 같은 것을 만들 수 있지 않을까(・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']; ? >
appid 변수에 게임 타이틀의 번호를 입력합니다. 이 번호는 스팀 게임 스토어 페이지의 url을 보면 알 수 있습니다.
이 api에서는 게임 타이틀 1개에 대한 정보만 얻을 수 있기 때문에(아마도) 불편할 것 같습니다.