← 記事に戻る
# 自身がフォローしているTwitterアカウントでリスト自動仕分けする方法!?

昨日は雨がシトシトと降っていた高知県ですが、あまり寒さを感じなくなってきていますね😌。早く春になれば良いのになって思っております。

ソースコードを読んでいただければ大体分かるかとも思いますが、そんなに難しいコードではありません。タイトル通りの処理をしています。コマンドからファイルを叩くと処理が実行されてそれぞれのリストに仕分けされます、ここでポイントなのはlist\_idはどうやって導けばよいのという疑問とTwitterOAuthって何という疑問ぐらいかと思います。

![](https://zip358.com/wp-content/uploads/2022/01/SnapCrab_NoName_2022-1-23_16-9-6_No-00.png) list\_idは事前に空のリストを生成すると自動的に割り振られるご自身のリストURLの数値部分になります。次に[TwitterOAuth](https://github.com/abraham/twitteroauth "TwitterOAuth")というのは何かというと、これは[TwitterAPI](https://help.twitter.com/ja/rules-and-policies/twitter-api "TwitterAPI")を簡単に叩けるライブラリになります。これを事前にインストールすることにより簡単に処理ができます。

> リストを生成してみた!! [pic.twitter.com/B7cXd6esLn](https://t.co/B7cXd6esLn)
> 
> — 田岡 寿章@taoka\_toshiaki🦌 (@taoka\_toshiaki) [January 23, 2022](https://twitter.com/taoka_toshiaki/status/1485141022266982401?ref_src=twsrc%5Etfw)



尚、ソースコードはTwitterAPI2.0バージョンではありません。そのうち廃止される方で書いています。

```
<?php
require_once("../vendor/autoload.php");

use Abraham\TwitterOAuth\TwitterOAuth;

if ($argv[0]) {
    require_once "./tw-config.php";

    date_default_timezone_set('Asia/Tokyo');
    $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
    $response_followers = $connection->get("friends/ids", array(
        'screen_name' => 'zip358com',
        'count' => 1000
    ));
    if ($response_followers->ids) {
        foreach ($response_followers->ids as $key => $val) {
            $response_users = $connection->get("users/show", array(
                'user_id' => $val
            ));
            if(preg_match("/(機械学習|人工知能|AI|Learning)/",$response_users->description)){
                print "[機械学習|人工知能|AI|Learning]". $response_users->id . PHP_EOL . $response_users->description . "," . PHP_EOL;
                $connection->post("lists/members/create", array(
                    'list_id'=>1485120628206497798,
                    'user_id'=>$response_users->id
                ));
            }
            if(preg_match("/(web|WEB|Web|プログラマー|エンジニア|プログラム|プログラミング|API)/",$response_users->description)){
                print "(web|WEB|Web|プログラマー|エンジニア|プログラム|プログラミング|API)". $response_users->id . PHP_EOL . $response_users->description . "," . PHP_EOL;
                $connection->post("lists/members/create", array(
                    'list_id'=>1485121383101526018,
                    'user_id'=>$response_users->id
                ));
            }
            if(preg_match("/(イラスト|写真|デザイン|art|Art|絵|漫画)/",$response_users->description)){
                print "(イラスト|写真|デザイン|art|Art|絵|漫画)". $response_users->id . PHP_EOL . $response_users->description . "," . PHP_EOL;
                $connection->post("lists/members/create", array(
                    'list_id'=>1485121210816294912,
                    'user_id'=>$response_users->id
                ));
            }
            if(preg_match("/(電車|メトロ|運行情報)/",$response_users->description)){
                print "(電車|メトロ)". $response_users->id . PHP_EOL . $response_users->description . "," . PHP_EOL;
                $connection->post("lists/members/create", array(
                    'list_id'=>1485121509320687619,
                    'user_id'=>$response_users->id
                ));
            }            
            if(preg_match("/(高知県|高知市)/",$response_users->description)||preg_match("/(高知県|高知市|kochi)/",$response_users->location)){
                print "(高知県|高知市)". $response_users->id . PHP_EOL . $response_users->description . "," . PHP_EOL;
                $connection->post("lists/members/create", array(
                    'list_id'=>1485121289165893632,
                    'user_id'=>$response_users->id
                ));
            }                        
        }
    }
}
```



 [ ![](https://zip358.com/wp-content/uploads/2026/01/image-31.png) サイトを分離した話を黙々と書いていきます.

 ](https://zip358.com/2026/02/04/%e3%82%b5%e3%82%a4%e3%83%88%e3%82%92%e5%88%86%e9%9b%a2%e3%81%97%e3%81%9f%e8%a9%b1%e3%82%92%e9%bb%99%e3%80%85%e3%81%a8%e6%9b%b8%e3%81%84%e3%81%a6%e3%81%84%e3%81%8d%e3%81%be%e3%81%99.html) 

 [ ![](https://zip358.com/wp-content/uploads/2026/01/image-30-300x300.png) 半額セールでアドビ様を延長.

 ](https://zip358.com/2026/02/03/%e5%8d%8a%e9%a1%8d%e3%82%bb%e3%83%bc%e3%83%ab%e3%81%a7%e3%82%a2%e3%83%89%e3%83%93%e6%a7%98%e3%82%92%e5%bb%b6%e9%95%b7.html) 

 [ ![](https://zip358.com/wp-content/uploads/2026/01/image-29.png) 何の前触れもなく変えたのは初めてかも.

 ](https://zip358.com/2026/02/02/%e4%bd%95%e3%81%ae%e5%89%8d%e8%a7%a6%e3%82%8c%e3%82%82%e3%81%aa%e3%81%8f%e5%a4%89%e3%81%88%e3%81%9f%e3%81%ae%e3%81%af%e5%88%9d%e3%82%81%e3%81%a6%e3%81%8b%e3%82%82.html) 

 [ ![](https://zip358.com/wp-content/uploads/2023/01/you-300x300.png) 跳ねたいサイトで跳ねたい

 ](https://zip358.com/2026/02/01/%e8%b7%b3%e3%81%ad%e3%81%9f%e3%81%84%e3%82%b5%e3%82%a4%e3%83%88%e3%81%a7%e8%b7%b3%e3%81%ad%e3%81%9f%e3%81%84.html) 

 [ ![](https://zip358.com/wp-content/uploads/2026/01/image-36.png) 映画、機動戦士ガンダム 閃光のハサウェイ キルケーの魔女

 ](https://zip358.com/2026/01/31/%e6%98%a0%e7%94%bb%e3%80%81%e6%a9%9f%e5%8b%95%e6%88%a6%e5%a3%ab%e3%82%ac%e3%83%b3%e3%83%80%e3%83%a0-%e9%96%83%e5%85%89%e3%81%ae%e3%83%8f%e3%82%b5%e3%82%a6%e3%82%a7%e3%82%a4-%e3%82%ad%e3%83%ab%e3%82%b1.html)