見出し画像

#D-TW02 ツイッターのデータを理解する (Understand twitter data)

(English follows)
というわけでまずは、どんな順番でデータ分析を行っていくのかの手順からスタートします。このシリーズでは具体的なコードにはあまり触れずに、難しくならないように説明をしていこうと思っています。Twitter分析ツールができるまでのフローはこんな感じでした。長い道のりだった。。。

そして今回は最初のデータを理解するところについてやってきたことを書いてみようかと。

  1. ツイッターを使い倒した

  2. ツイッターのどんなデータが取れるのか

  3. ツイッターから取れるデータの制約

ツイッターを使い倒した
何しろ最初はツイッターというものがあまり分かってなかったので、昔作って放置していたアカウントでいろいろな人をフォローしてどんなことを書いているのか、検索するとどんなデータが引っ張られるのかを試してみました。いまやツイッターに一日何時間も向き合うきっかけになってしまって後悔してます。。。ま、YouTubeの時間と取引されました(笑)
炎上したと聞くとそれをわざわざ見に行ったりもしました。病む、この世界は。。。その中でどんなデータは将来掃除したほうが分析が楽しくなるかとか、どんな検索をすると面白い情報を取れそうかなどのコツを掴んでいきました。例えば言語を指定した検索はできるけど、例えば国を指定した検索はできないので、日本語であればほぼ日本なので問題ないですが、英語だと世界中の情報が出てきてしまい、シンガポールの声みたいにはデータ収集できないことが分かったりしました(残念)。さらにテキストのついた画像で表現されている方も多くてそれもテキストとして取るのは(簡単には)無理そうでした(残念)

どんなデータがツイッターからいただけるのか?
次はTwitterの開発者用のページ(ここ)に行き、中身を勉強しました。英語が苦手じゃなくてよかった。そもそもページに行ったらAPI(部品)がたくさんあって、どれが目的のものなのかを探すのから大変でした。目的のものは Search tweets APIというものでした。で、目的の項目は「Response fields」のところにありました。ユニークIDとテキストの他にも時間や、ユーザーアカウント、もし許諾を出していれば地理情報なども取れそうでした。

ツイッターからいただけるデータの制約
後はデータの制約や、形でしょうか。今回の場合無料APIの制約というものがありました。無料版では直近7日分のデータしか触れないとか、さらに月間50万件のツイートしかとれない(Tweet API v2では)、15分の間に450リクエスト(後述)しか投げれない、あとなんとなく匂わされているのが、検索では本当にすべてのツイートが取れているわけではないという感じでしょうか。
形としては今は殆どのAPIがそうですが、Jsonというフォーマットで、一回問い合わせをすると最大100件まだ結果を返してくれるという感じのようです。それ以上取るにはもう一度次のページに行くという問い合わせをするイメージです。基本的には最新のデータから返してくれるようなので、毎日すでに持っているツイート番号に到達するまでデータを取り続ければ未来に渡ってはいくらでもデータは貯められそうです。しかしその場合消えてしまったツイートも残ってしまうことにはなりそうです。

すでに長くなってしまったので、どのように設計したかは次のポストに持ち越しましょう。いやいや、短く書くのが難しすぎますね。

Let me show you how did I made the analysis system for twitter text data. In this series, I will try not to touch the actual programming code to make it as easy as possible to understand. Below is the flow. It was … really long. Hahahaha.

Then I will write about data understanding in this post. Basically what I have done but should not be the "only" way, sorry.

  1. Used twitter heavily

  2. What type of data we can get from Twitter

  3. Limitation on data we can get from twitter

Used twitter heavily
I hadn't used twitter, so I started from following many accounts to see what people actually tweet and how does the search work. Well It pushed me into deep into chaotic twitter world and let me spend long time in a day. I truly regret about it… It was offset by time to watch YouTube (Smile).
When I heard that there was a fire, I went all the way to see how people react to those tweets which was really exhausting mentally energy consuming. I don't recommend you to look at those tweets for long time for your mental health. Then I got to understand what would be the interesting point to analyze twitter data, what are the potentially interesting words to search for. For example, I found that you can search by language but not by country. Practically there is not difficulties for Japan since Japanese are mostly spoken in Japan, but it is very difficult for English to get data for example from Singapore (Sad). 

What type of data we can get from Twitter
Then I opened Twitter developer site to get the structure of data we can get (Here). Nice that I can read English since information is provided only in English. However there are so many APIs there and I took me quite a while to understand which API I was looking for. What I needed was "search tweets API" and information needed was in "Response fields". It seems I can get Tweet Unique ID, Text, time stamp, user account name, geo code etc.

Limitation on data we can get from twitter
Finally I had to know the limitation of data and format. In this case, there are few limitation because I was going to use free API. With the free API, I can only touch to latest 7 days data, "only" 500K tweets in a month, "only" 450 requests per 15 minutes (Tweet API  v2) also it is implied that not all tweet can be retrieved by the search.
Format of data is "Json" which is commonly used for API data exchange and when I make one request, the API give 100 tweets back. So If you need more you have to make the next request for the "next page". That API give us from the latest data. So although you can not touch the past data (more than 7 days before), you can pile up the data by running the program everyday. One thing would be the data base should have past tweets data which are deleted.

Thank you vey much for reading the long post. Next one would be about "data collection" part. 

この記事が気に入ったらサポートをしてみませんか?