Easily post to twitter with Python 3

Introduction

I wanted to post automatically from python to twitter, so I investigated the posting method using twitter API and API cooperation library. python uses 3.x series.

Get API key and access token

Register a new app on the following site for app developers. Twitter Application Management

Get the key and access token you need and make a note of it.

Library installation

There is a twitter API cooperation library for python. This time, I used the following simple library. sixohsix/twitter


#Install pip (without pip)
easy_install pip

#Install the library using pip
pip install twitter

Post program sample in python

twitter_post_sample.py


#coding: UTF-8

import twitter

#Set the obtained key and access token
auth = twitter.OAuth(consumer_key="XXX",
                     consumer_secret="XXX",
                     token="XXX",
                     token_secret="XXX")

t = twitter.Twitter(auth=auth)

#Post a message to twitter
t.statuses.update(status="This is a post test from python to twitter!")

Recommended Posts

Easily post to twitter with Python 3
Post to slack with Python 3
Post to Twitter using Python
[Lambda] [Python] Post to Twitter from Lambda!
Post multiple Twitter images with python
Steps to create a Twitter bot with python
Post an article with an image to WordPress with Python
Connect to BigQuery with Python
Post to vim → Python → Slack
Easily serverless with Python with chalice
Twitter graphing memo with Python
Get Twitter timeline with python
POST json with Python3 script
Use Twitter API with Python
Connect to Wikipedia with Python
Switch python to 2.7 with alternatives
Write to csv with Python
Search twitter tweets with python
Post to Slack in Python
Try hitting the Twitter API quickly and easily with Python
Python: How to use async with
Link to get started with python
[Python] Write to csv file with Python
Create folders from '01' to '12' with python
Nice to meet you with python
Try to operate Facebook with Python
Easily implement subcommands with python click
Post from python to facebook timeline
Easily handle lists with python + sqlite3
Output to csv file with Python
[Python] POST wav files with requests [POST]
Quine Post with Qiita API (Python)
Convert list to DataFrame with python
How to get started with Python
Post a message to Google Hangouts Chat with a thread (Python)
What to do with PYTHON release?
Post images from Python to Tumblr
Unable to install Python with pyenv
Easily handle databases with Python (SQLite3)
How to calculate date with python
[Python] Collect images easily with icrawler!
[Nanonets] How to post Memo [Python]
I want to debug with Python
[Memo] Tweet on twitter with python
I made a library to easily read config files with Python
I tried to make a 2channel post notification application with Python
Collecting information from Twitter with Python (Twitter API)
Try to reproduce color film with Python
Try logging in to qiita with Python
Change Python 64bit environment to 32bit environment with Anaconda
English speech recognition with python [speech to text]
Convert memo at once with Python 2to3
HTML email with image to send with python
Memo to ask for KPI with python
Python to remember only with hello, worlds
Output color characters to pretty with python
Introduction to Python Image Inflating Image inflating with ImageDataGenerator
POST variously with Python and receive with Flask
Output Python log to console with GAE
Tweet from python with Twitter Developer + Tweepy
Convert Excel data to JSON with python