Photo by Pixabay on Pexels.com

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

20240827

Logging

おはようございます.xAIの申請に通らなかったので来月のQiitaの投稿を何にしようかなと考えてた所、ふと積みゲーのことが頭に浮かんできたので、Steam APIとかあるのかなと調べてみました.そしたらAPIが在ったのでさっそく作ってみました.

ソースコードはgithubにもあげているので試してみてください.こちらのソースコードをコピペするよりお手軽ですよ.

https://github.com/taoka3/steam/tree/main

<?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();

    

因みに実行結果は下記になります.

明日へ続く.

著者名  @taoka_toshiaki

Profile
高知県在住の@taoka_toshiakiです、記事を読んで頂きありがとうございます.
数十年前から息を吸うように日々記事を書いてます.たまに休んだりする日もありますがほぼ毎日投稿を心掛けています😅.
SNSも使っています、フォロー、いいね、シェア宜しくお願い致します🙇.
SNS::@taoka_toshiaki

タグ

$params, APIKEY, foreach, getOwnedGames, github, gt, int, json_decode, lt, php require, printf, public, qiita, response, result, return, STEAMID, URLs, val, xAI,