Back to tech

Pythonでツイート

1 min read
Table of Contents

Pythonでツイートするためのプログラムです
pythonにtwythonをimportしてください Python Tweets_Python.py “ツイートしたいメッセージ” でツイートできます

consumerKey = ”— Your consumerKey —” consumerSecret = ”— Your consumerSecret —” accessToken = ”— Your accessToken —” accessSecret = ”— Your accessSecret —” には各自でTwitterAPIを取得してください

プログラム

# -*- coding: utf-8 -*-

import twython
import sys

def main(str_tweet):
  consumerKey = "-- Your consumerKey --"
  consumerSecret = "-- Your consumerSecret --"
  accessToken = "-- Your accessToken --"
  accessSecret = "-- Your accessSecret --"

  api = twython.Twython(app_key=consumerKey,
                app_secret=consumerSecret,
                oauth_token=accessToken,
                oauth_token_secret=accessSecret)

  try:
      api.update_status(status=str_tweet)
  except twython.TwythonError as e:
      print e


if __name__ == '__main__':
  mes = sys.argv
  main(mes[1])