PythonでTwitter APIを使ってツイートする最低限の手順を記します。
Python 3.5.1で動作確認済みです。
アプリの新規登録、Access tokenの取得
以前書いたRuby版の記事があるので、参考にしてください。
RubyでTwitter APIを使ってツイートする
Twitter APIにアクセスする為のPythonパッケージのインストール
コマンドラインで以下のコマンドを実行します。
$ pip install python-twitter
Pythonのコード
tweet.py
# -*- coding: utf-8 -*-
import twitter
api = twitter.Api(consumer_key="Consumer Keyを入力",
consumer_secret="Consumer Secretを入力",
access_token_key="Access Tokenを入力",
access_token_secret="Access Token Secretを入力"
)
api.PostUpdate("tweet from my app")
ツイートする
$ python3 tweet.py