2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

steamのAPIを使用して積みゲーを調べてみた.

Posted at

まず前提条件としてsteamのAPIを使用するにはsteamの商品をある一定の金額以上購入している人しか使えないみたい.
APIの登録は下記のリンクから可能です.

登録が終わったら登録したドメインから下記のソースコードを実行します.
なお、コンフィグ値はご自身にあった値へ変更してください.

steam.php
<?php
require 'config.php';

class steam
{

    public $result;

    public function getOwnedGames($urls = 'http://api.steampowered.com/IPlayerService/GetOwnedGames/v1/?')
    {
        $params = http_build_query([
            'key'=>APIKEY,
            'steamid'=>STEAMID,
            'include_appinfo'=>1,
            'include_played_free_games'=>0,
            //'appids_filter'=>''
        ]);
         $this->result = file_get_contents($urls.$params,true);
         return $this;
    }

    public function viewOwnedGames()
    {
        $data = json_decode($this->result);
        
        foreach($data->response->games as $val){
            $tumiGames = (int)$val->playtime_forever === 0?' [積みゲー]':'';
            printf('ゲーム名:%s プレイ時間:%02d時%02d分%s<br>',$val->name,(int)($val->playtime_forever / 60),(int)($val->playtime_forever % 60),$tumiGames);
        }
        return $this;
    }
}

(new steam)->getOwnedGames()->viewOwnedGames();
config.php
<?php
define('APIKEY','');
define('STEAMID','');

因みに自分の結果はこんな感じですw

image.png

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?