なろう分析記録

『小説家になろう』をふくめ『ネット小説投稿サイト』を分析する。コード置き場,主にPython,javascript,たまに創作。

【2019年版】Twitter API Keyの申請から取得とtweepyでツイートするサンプルコード

この度ツイッターTwitter API Keyを取得したので、そのやりとりの記録とPythonTwitter API Keyを使ってツイートするサンプルコードを紹介したいと思います。

f:id:karupoimou:20190516072851p:plain
tweepyでのツイート


Twitter API Keyの申請から取得

まず「Twitter developer」のページから登録申請を行います。
なおやりとりは全て英語で行う事となっています。

Developer

API Keyの申請が通るまでのメモ

5月14日(火) 16:37

Twitter developerページから申請

5月14日(火) 16:38

Application under review. の自動返信メール着

5月14日(火) 22:46

一回目の返答メール

Thanks for applying for access!


In order to complete our review of your application, we need additional information about your use case. The most common types of information that can help expedite our review include:


The core use case, intent, or business purpose for your use of the Twitter APIs

If you intend to analyze Tweets, Twitter users, or their content, share details about the analyses you plan to conduct and the methods or techniques

If your use involves Tweeting, Retweeting, or liking content, share how you will interact with Twitter users or their content

If you’ll display Twitter content off of Twitter, explain how and where Tweets and Twitter content will be displayed to users of your product or service, including whether Tweets and Twitter content will be displayed at row level or aggregated


To provide this information to Twitter, reply to this email.


Thank you for your interest in building on Twitter.

返信した内容の要約

主な目的は特定のwebページの更新をツイートすることです
特定のwebページの更新を通知するだけの機能を持ったbot作成が目的です
ツイートの分析はしません
他のユーザーとのやりとりもしません
テキストだけつぶやくことだけに使います

5月15日(水) 23:11

二回目の返答メール

Thank you for your response.

At this time, we still do not have enough specific information about your intended use case to complete review of your application. As a reminder, we previously requested additional information about:

The core use case, intent, or business purpose for your use of the Twitter APIs

Note that “business purpose” in this context includes uses not necessarily connected to a commercial business. We require information about the problem, user story, or overall goal your use of Twitter content is intended to address.

If you are a student, learning to code, or just getting started with the Twitter APIs, please provide details about potential projects or areas of focus.

If you intend to analyze Tweets, Twitter users, or their content, share details about the analyses you plan to conduct and the methods or techniques

Note that “analyze” in this context includes any form of processing performed on Twitter content. Please provide as detailed and exhaustive an explanation as possible of your intended use case.

If your use involves Tweeting, Retweeting, or liking content, share how you will interact with Twitter users or their content.

If you’ll display Twitter content off of Twitter, explain how and where Tweets and Twitter content will be displayed to users of your product or service, including whether Tweets and Twitter content will be displayed at row level or aggregated

Where possible, please share links to illustrations and/or sample work products. Note that we can’t view attachments.

To provide this information to Twitter, reply to this email. Failure to provide the necessary information will result in the rejection of your application.

Thank you for your interest in building on Twitter.

返信した内容の要約

ただ特定のウェブページの更新を通知するだけの目的で使用します。
ビジネス目的ではなく、個人的なホビーユースです。
他のユーザーとのやりとりはしません。
ツイートの分析もしません。
サンプル画像をgoogleドライブにアップしたから以下のURLから見てください。
https://drive.google.com/file/d/1We8BEUmlidMot_NyV6pao-J72U7brAaY/view

f:id:karupoimou:20190516080518p:plain:w200

5月16日(木) 5:21

Account Application Approvedのメール着
申請受理!

Twitter API Key申請から受理までの要約

申請5月14日(火) 16:37

↓2回メールのやり取り

受理5月16日(木) 5:21

ネット上ではTwitter API Keyの申請から受理までに掛かる時間について約一週間ぐらいという記事が多かったですが、今回は約3日で入手できました。
使用目的にもよるのかもしれませんが、わりと早く入手できたと思います。

ツイッター社からの返答メールはコピペ文ですね。

以下、テストツイートのサンプルコード。

ツイートテスト用のサンプルコード

tweepyのインストール

pip install tweepy

#ツイートテスト用のサンプルコード
import tweepy

# KEYの指定
CONSUMER_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
CONSUMER_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
ACCESS_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
ACCESS_TOKEN_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# tweepyの設定
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)

#ツイートの実行
api.update_status("テストツイート")

tips

改行コードは「\n」

コード

api.update_status("テストツ\nイート")

結果

f:id:karupoimou:20190516073136p:plain
結果