※2020年2月11日更新済み
今回はTwitterのAPIについて、かなり丁寧に!かなりわかりやすく!解説していきます!
少しだけ前置きが長めにあったりするので、とにかくすぐにAPIが使いたい、登録方法が知りたい。って思っている方はこちらから読み進めてください。
新しくなったTwitterのAPI
APIの規制が厳しくなった
Twitterは2018年7月24日、APIの使用条件を変更すると発表しました。この発表によりこれまで使えていたTwitterのAPIは使うことができなくなってしまいました。
新しいTwitterのAPIではかなり規制が厳しくなり、登録するのにも一苦労といったかんじです。
開発者の間では、「制限が厳しすぎる」、「Twitterは、サードパーティによるAPI利用を締め出したいのでは」 、などといった声が上がっているそうです。
具体的な使用制限
2018年9月10日以降では以下のような制限が設定されます。
ツイートとリツイート(合算値):3時間で300件
いいね:24時間で1000件
フォロー:24時間で1000件
ダイレクトメッセージ:24時間で1万5000件
これはかなり厳しくなってしまったのではないかと思っています。
Twitterはサーバー代がかなりバカ高く、会社自体があまり儲かっていないという話も聞きますが、こう行った理由から、制限をかけざるを得ない状況になってしまったのでしょうか。
関連記事→Twitter、API使用条件を厳格化 「厳しすぎる」開発者から悲鳴も
Twitter API仕様変更の反応
TwitterのAPI制度変更に関してどのような声が上がっているのか調査して見ました。これからTwitterはどのような方向に行くのでしょうか。
Twitter bot、実は今API制限で新規登録するときは開発者登録とTwitterによる審査とかしなくちゃならなくて難しいんよね…
— ウラル (@barley_ural) August 27, 2018
Twitterのapi規制
なかなか難しいですね— miya ブロックチェーン勉強中 (@miya_chain0110) September 16, 2018
ちなTwitterの関連ツールは簡単に言うとご本家のAPI縛りが厳しく作るのが難しいらしい。道理でユーザー数の割に雑なツールが少ないわけだよね
— 鉄騎坊主 (@TBPriest) July 7, 2018
TwitterAPIの新しい規制のやつ、ざっとよんだかんじそんな問題なさそうだったけどな。審査でOKでればほとんど今までと変わらないユーザーごとの制限のみらしいし。審査しだいっすね。
— \そや/ (@1000tea) July 26, 2018
みなさんかなりTwitterのAPI取得に苦しんでいるようです。
TwitterのDeveloper登録手順
では早速本題のTwitter APIの登録手順について説明していきましょう。
Twitter Developerサイトにアクセス
まずはTwitterのDeveloperツールを利用するために会員登録をします。
今回ツイートを自動化するときに使いたいTwitterアカウントを用意してください。
こちらのリンクから登録できます。
Twitter Developer Platform — Twitter Developers
右上の「Apply」をクリックします。

「Apply for a developer account」をクリックします。

Interested in a developer account?
「Interested in a developer account?」という表示が出てきたら、中央に表示されているアカウントが自動化ツールで使用したいTwitterアカウントと同じかどうか確認してください。

確認し、OKだったら「Continue」をクリック。
Add your account details
「Add your account details」は、法人なら上、個人なら下を選択します。
「Account name」は自分の自由なアカウント名を
「Primary country of operation」は「Japan」を選択します。

Tell us about your project
「Tell us about your project」とありますが、そのプロジェクトではどんなことをやるのかが聞かれています。
「What use case(s) are you interested in?」ではどんな目的で使うのかを選択します。なんでも大丈夫です。

Publish and curate Tweets
「Publish and curate Tweets」は300文字以上で英語を書かなければいけません。

書く内容は以下の通り
- TwitterのAPIの使用理由
- ツイートとかユーザーを分析するんですか?もしそうならどうやってやる予定ですか
- ツイート、リツイート、ファボをしますか?やるならどうやってやる予定ですか?
- どうやって分析したツイッターデータを表示させますか?
英語で大変だとは思いますが、Google翻訳でも使って頑張って見てください。
一応適当なことを書いてもとおるっちゃ通ります。
ちなみに私はこんな感じにかきました(テキトーです)
・日本語
私はブログをやっているのですが、ブログを盛り上げるためにTwitterを活用しています。
Twitterを活用し、ユーザーのデータを取得したりいいねしたりすることで、多くの人と繋がり自分のブログを知ってもらおうと考えています。
自動でいいねしたり、自動でフォローするような機能を作って作業をより効率化したいです。
・英語
I am doing a blog, but I use Twitter to make my blog exciting.
By utilizing Twitter, acquiring user’s data and making it nice, I am thinking to connect with a lot of people and get to know my blog.
I would like to make the work more efficient by making functions like automatic nice or automatic follow-up.
「Will your product, service, or analysis make Twitter content or derived information available to a government entity?」
はNoを選択しましょう

利用規約
規約を読んだら、チェックを入れ「Submit application」をクリックしたら完了です。

メールが到着
このような画面がでてきたら完了です。自分のメールアドレスにメールが届いてると思います。

「Confirm your email」をクリックすると登録完了です。
TwitterAPI使用アプリの登録
Twitter APIの登録ができたら、次にアプリケーションの登録を行なっていきます。
「Create an app」をクリックします。

同じく「Create an app」です。

App details
App detailsっていうのがでてきたら必要事項を記入していきます。

多分全部テキトーで大丈夫です。
最後の「Tell us how this app will be used 」だけは100文字以上の英語で記入しなければいけないので注意です。

・日本語
私はブログをやっています。ブログを盛り上げるためにTwitterを使おうと思っています。悪用はしないので心配しないでください。
・英語
I am doing a blog. I am planning to use Twitter to boost my blog. Do not worry because you will not exploit it.
API Keyを取得
「API and tokens」の画面に行くとAPI key が取得できます。
Access token & access token secretはデフォルトで用意されていません。「Create」を押してキーを発行しましょう。

以上がTwitter APIの登録方法でした。英語がかなり出てきてわかりずらかったと思いますが頑張って慣れることが大事ですね。
もっと発展的なAPIの知識を身に付けたい人向け
今回はTwitter APIをご紹介しました。APIの使い方はそれなりにメジャーなサービスでない限り、日本語でわかりやすく丁寧な説明があることは少ないです。
実際、エンジニアとして活躍していくためにはAPIの知識と、それをどう使いこなせるかがかなり重要になってきます。また、APIに詳しくなっておくと、一見難しそうなアプリも1日で作れるようになったりなど、効率的に仕事を行えます。
もっとAPIの知識を身に付けたい方はTech Boost(テックブースト)の受講がおすすめです。