2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CoreTweetとADGVでたくさんブロックするツール作ったので覚書

Posted at

ひどいツール作ったのでメモ兼ねてポイント残しておきます。

経緯

ツイッターで#~と繋がりたいとか、裏垢なんちゃらとかスパムアカウントをまとめてブロックしたかったのです。

作ったもの

image.png
名前はTwitterブロックんです。

キーワード検索をすると、該当のフレーズをツイートしているアカウントを抽出します。
image.png

使っているグリッドはADGVです。nugetからインストール出来ます。
インストールしたあとは、コンポーネントとして使用できるようにするためにツールボックスからDLLを読み込んでください。
Image from Gyazo

あとはCoreTweetも同じようにnugetからインストールしてusingに追加すればOKです。

ADGVの初期化は下記の感じ

                _dataTable = _dataSet.Tables.Add("Table");
                _dataTable.Columns.Add("ブロック対象", typeof(Boolean));
                _dataTable.Columns.Add("ユーザーID", typeof(string));
                _dataTable.Columns.Add("ユーザー名", typeof(string));
                _dataTable.Columns.Add("ツイート内容", typeof(string));
                bindingSource_main.DataMember = _dataTable.TableName;

ユーザー検索はこんな感じで色々他のユーザーさんが用いている内容そのままです。
C#でTwitterアプリを作る 第2回 Timeline / Status - らこらこブログ

CoreTweetでPINを取得してツイートする方法(OAuthによるトークン発行) - Qiita


            // グローバル検索
            string keyword = textBox2.Text;
            if (!keyword.Equals(""))
            {
                _dataTable.Clear();
                var result = tokens.Search.Tweets(count => 100, q => keyword);
                // countは読み込み数。指定しなければDefoultの数値が入る。
                foreach (var value in result)
                {
                    string scrName = value.User.ScreenName;     // @User_ID
                    string name = value.User.Name;              // ユーザー名
                    string text = value.Text;                   // Tweet
                    AddUserData(false, scrName, name, text);
                }
            }
        private void AddUserData(Boolean check, string scrName, string name, string text)
        {
            try
            {
                object[] newrow = new object[] {
                        check,
                        scrName,
                        name,
                        text
                };
                _dataTable.Rows.Add(newrow);
                Application.DoEvents();
            }
            catch
            {
            }
        }

ブロックはこれだけで出来ます。CoreTweet便利。
catchでエラー処理とかちゃんとしないとですね。

                for (int i = 0; i < advancedDataGridView_main.RowCount; i++)
                {
                    if (Convert.ToBoolean(advancedDataGridView_main.Rows[i].Cells[0].Value))
                    {
                        try
                        {
                            tokens.Blocks.Create(screen_name => advancedDataGridView_main.Rows[i].Cells[1].Value);
                        }
                        catch
                        {

                        }
                    }
                }

まとめ

CoreTweet凄い便利。ADGVも便利。
1時間ぐらいである程度形になるものにはなるので面白かったです。

2
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?