LoginSignup
19
18

More than 5 years have passed since last update.

PythonでTwitter APIを使ってツイートする

Last updated at Posted at 2016-07-16

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

19
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
18