Tweet用モジュール。Twitter API V2対応。
PythonでTweetするモジュールです。
対応しているエンドポイントは、2023.04.05時点で以下の通りです。
https://api.twitter.com/2/tweets
メディアアップロードも出来ますが、V2版はまだリリースされていません。公式案内のとおり、旧API(V1.1)を利用しています。 リリースされ次第対応します。
テキストのみのTweetしたいとき、画像付きでツイートしたいとき。
requestsとrequests_oauthlibがインストールされている必要があります。
pip install requests requests_oauthlib
{
"API_KEY": "MY-API-KEY",
"API_SECRET": "MY-API-SECRET",
"BEARER": "MY-BEARER",
"ACCESS_TOKEN": "MY-ACCESS-TOKEN",
"ACCESS_SECRET": "MY-ACCESS-SECRET"
}
プロジェクトのほうではpytweet/
を.gitignoreしておくと良いかも?
git clone https://github.com/zenryokukun/pytweet.git
from pytweet import Pytweet
twitter = Pytweet("path-to-your-twitter-credential-file")
# tweet with text only
twitter.tweet("hello,world!")
# tweet with images
twitter.tweet("hello,world","path-to-img1",...,"path-to-img4")