0
0

More than 1 year has passed since last update.

任意のユーザーのQiitaのfeedを取得し表示するコード😋

Last updated at Posted at 2022-11-03

SnapCrab_NoName_2022-11-3_14-6-20_No-00.png

コードを書いた経緯と注意点

  • Qiitaのfeedを取得する方法は書かれているけど任意のユーザーはあまり見かけないので記載しました。
  • ご自由に使用下さい。また人様のfeedを掲載する時は引用が必要です。引用が駄目だと言う方もいらっしゃるかもしれないですね🫠
index.php
<?php
    function get_Qiitafeed(string $feedUrl){
        $xml = @simplexml_load_file($feedUrl);
        if(isset($xml->entry)){
            print("<ul class='qiita_feed-list'>");
            foreach($xml->entry as $key=>$val){
                print("<li><a href='{$val->url}'>".$val->title."</a></li>");
            }
            print("</ul>");
        }
    }
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="Description" content="Enter your description here"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<style>
    .qiita_feed-list > li{
        /* font-weight: bold; */
        color:aliceblue;
    }
    .qiita_feed-list > li > a{
        color:aliceblue;
    }
    body{
        background-color:#60b111;
    }
    .shadow-lg {
        box-shadow: 0 1rem 3rem rgba(255,255,255,.195)!important;
    }    
</style>
<title>Qiita-feed</title>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-12">
                <h1 class="text-light">Qiita-feed</h1>
            </div>
        </div>
    </div>
    <div class="container mt-2">
        <?php
            $Id_List = ["taoka-toshiaki","mpyw","suin"];
            foreach ($Id_List as $key => $id) {
            ?>
        <div class="row shadow-lg p-3 mb-5 bg-body rounded">
            <div class="col-12">
                🌿<span class="text-light">://qiita.com/<?=$id?>/feed :[引用]</span>
                <?=get_Qiitafeed("https://qiita.com/".$id."/feed")?>
            </div>
        </div>            
            <?php
            }
        ?>

    </div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.min.js"></script>
</body>
</html>
var_dump:$xmlの中身はこんな感じです。
    object(SimpleXMLElement)#1 (6) {
  ["id"]=>
  string(39) "tag:qiita.com,2005:/taoka-toshiaki/feed"
  ["link"]=>
  array(3) {
    [0]=>
    object(SimpleXMLElement)#2 (1) {
      ["@attributes"]=>
      array(3) {
        ["rel"]=>
        string(9) "alternate"
        ["type"]=>
        string(9) "text/html"
        ["href"]=>
        string(17) "https://qiita.com"
      }
    }
    [1]=>
    object(SimpleXMLElement)#3 (1) {
      ["@attributes"]=>
      array(3) {
        ["rel"]=>
        string(4) "self"
        ["type"]=>
        string(20) "application/atom+xml"
        ["href"]=>
        string(37) "https://qiita.com/taoka-toshiaki/feed"
      }
    }
    [2]=>
    string(32) "https://qiita.com/taoka-toshiaki"
  }
  ["title"]=>
  string(31) "taoka-toshiakiの記事 - Qiita"
  ["description"]=>
  string(58) "Qiitaでユーザーtaoka-toshiakiによる最近の記事"
  ["updated"]=>
  string(25) "2022-11-03T08:10:34+09:00"
  ["entry"]=>
  array(4) {
    [0]=>
    object(SimpleXMLElement)#4 (8) {
      ["id"]=>
      string(40) "tag:qiita.com,2005:PublicArticle/1637649"
      ["published"]=>
      string(25) "2022-11-03T08:10:34+09:00"
      ["updated"]=>
      string(25) "2022-11-03T11:03:25+09:00"
      ["link"]=>
      object(SimpleXMLElement)#8 (1) {
        ["@attributes"]=>
        array(3) {
          ["rel"]=>
          string(9) "alternate"
          ["type"]=>
          string(9) "text/html"
          ["href"]=>
          string(59) "https://qiita.com/taoka-toshiaki/items/d6bc1ab1b97001becaa2"
        }
      }
      ["url"]=>
      string(59) "https://qiita.com/taoka-toshiaki/items/d6bc1ab1b97001becaa2"
      ["title"]=>
      string(129) "常時ディレクトリ監視を行い任意の画像ファイルだけ別のディレクトリへ移動するコードです。"
      ["content"]=>
      string(160) "コードを書いた経緯

while(true)の使い道を一つの例として記載しました。

https://github.com/taoka-toshiaki/change_dir
nohup php Fil…"
      ["author"]=>
      object(SimpleXMLElement)#9 (1) {
        ["name"]=>
        string(14) "taoka-toshiaki"
      }
    }
    [1]=>
    object(SimpleXMLElement)#5 (8) {
      ["id"]=>
      string(40) "tag:qiita.com,2005:PublicArticle/1629969"
      ["published"]=>
      string(25) "2022-10-10T08:18:00+09:00"
      ["updated"]=>
      string(25) "2022-10-10T08:18:00+09:00"
      ["link"]=>
      object(SimpleXMLElement)#9 (1) {
        ["@attributes"]=>
        array(3) {
          ["rel"]=>
          string(9) "alternate"
          ["type"]=>
          string(9) "text/html"
          ["href"]=>
          string(59) "https://qiita.com/taoka-toshiaki/items/c426ae8d3ab592cf6d8a"
        }
      }
      ["url"]=>
      string(59) "https://qiita.com/taoka-toshiaki/items/c426ae8d3ab592cf6d8a"
      ["title"]=>
      string(66) "cron(クロン)実行先でcron(クロン)一元管理👏"
      ["content"]=>
      string(187) "cron(クロン)先でcron(クロン)一元管理
https://github.com/taoka-toshiaki/cron-php
制作経緯

レンタルサーバー等のcronの制約を打破したいなと思…"
      ["author"]=>
      object(SimpleXMLElement)#8 (1) {
        ["name"]=>
        string(14) "taoka-toshiaki"
      }
    }
    [2]=>
    object(SimpleXMLElement)#6 (8) {
      ["id"]=>
      string(40) "tag:qiita.com,2005:PublicArticle/1628890"
      ["published"]=>
      string(25) "2022-10-06T15:49:05+09:00"
      ["updated"]=>
      string(25) "2022-10-27T17:50:10+09:00"
      ["link"]=>
      object(SimpleXMLElement)#8 (1) {
        ["@attributes"]=>
        array(3) {
          ["rel"]=>
          string(9) "alternate"
          ["type"]=>
          string(9) "text/html"
          ["href"]=>
          string(59) "https://qiita.com/taoka-toshiaki/items/7941f234f94fd506880a"
        }
      }
      ["url"]=>
      string(59) "https://qiita.com/taoka-toshiaki/items/7941f234f94fd506880a"
      ["title"]=>
      string(24) "稀に使うコード集"
      ["content"]=>
      string(214) "稀に使うコード集
ページ内のリンクアドレスを一括コピーします。
※googleやYOUTUBEページではコピーメソッドが使用できないようです。
copy([...document.querySele…"
      ["author"]=>
      object(SimpleXMLElement)#9 (1) {
        ["name"]=>
        string(14) "taoka-toshiaki"
      }
    }
    [3]=>
    object(SimpleXMLElement)#7 (8) {
      ["id"]=>
      string(40) "tag:qiita.com,2005:PublicArticle/1628544"
      ["published"]=>
      string(25) "2022-10-05T16:28:32+09:00"
      ["updated"]=>
      string(25) "2022-10-05T16:41:50+09:00"
      ["link"]=>
      object(SimpleXMLElement)#9 (1) {
        ["@attributes"]=>
        array(3) {
          ["rel"]=>
          string(9) "alternate"
          ["type"]=>
          string(9) "text/html"
          ["href"]=>
          string(59) "https://qiita.com/taoka-toshiaki/items/5ef12b60b267742bf584"
        }
      }
      ["url"]=>
      string(59) "https://qiita.com/taoka-toshiaki/items/5ef12b60b267742bf584"
      ["title"]=>
      string(43) "Twitterツイート管理システム試作"
      ["content"]=>
      string(270) "Twitterツイート管理システム試作
概要等は下記の記載をお読みください。ソースコードはgithubで公開しております。
尚、今回の管理システムは簡易版です、このシステムにツイッター認証などのシス…"
      ["author"]=>
      object(SimpleXMLElement)#8 (1) {
        ["name"]=>
        string(14) "taoka-toshiaki"
      }
    }
  }
}
0
0
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
0
0