LoginSignup
0
0

blueSkyのプロフィールURLからRSSを抽出するコードを書きました。

Last updated at Posted at 2024-01-17

blueSkyのプロフィールURLからRSSを抽出するコードです。

blueSkyがRSS対応という記事を見たので対応してみました。
php7系とphp8系なら恐らく動作すると思います。
動作環境はPHP8.2になります。

<?php
<?php
class blueSkyRss{
    public $rss = null;
    /**
     * __construct
     * @param $url
     * @return void
     */
    public function __construct($url)
    {
        try {
            $html = file_get_contents($url);
            preg_match('/https:\/\/bsky\.app\/profile\/did.*\/rss/',$html,$matches);
            if($rssUrl = $matches[0]){
                $feed = simplexml_load_file($rssUrl);
                $this->rss = $feed;    
            }
        } catch (\Throwable $th) {
            //throw $th;
        }
    }
    /**
     * getRss
     * @return object
     */
    public function getRss():object
    {
        $response = [];
        if(isset($this->rss->channel)){
            $cnt = 0;
            foreach($this->rss->channel->item as $item){
                $response[$cnt]['link']    = $item->link;
                $response[$cnt]['comment']   = $item->description;
                $response[$cnt]['date'] = $item->pubDate;
                $cnt++;
            }
        }
        return (object)$response;
    }
}
$url = 'https://bsky.app/profile/xxxxxxx.bsky.social';
//var_dump((new blueSkyRss($url))->getRss());
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