Tweet using the Twitter API in Python

Here are the minimum steps to tweet using the Twitter API in Python. It has been confirmed to work with Python 3.5.1.

New registration of application, acquisition of Access token

There is a Ruby version article I wrote before, so please refer to it. Tweet using Twitter API in Ruby

Install Python package to access Twitter API

Execute the following command on the command line. $ pip install python-twitter

Python code

tweet.py


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

import twitter


api = twitter.Api(consumer_key="Enter Consumer Key",
                  consumer_secret="Enter Consumer Secret",
                  access_token_key="Enter Access Token",
                  access_token_secret="Enter Access Token Secret"
                  )
api.PostUpdate("tweet from my app")

Tweet

$ python3 tweet.py




Recommended Posts

Tweet using the Twitter API in Python
Access the Twitter API in Python
Try using the Wunderlist API in Python
Try using the Kraken API in Python
Tweet Now Playing to Twitter using the Spotify API. [Python]
Try using the BitFlyer Ligntning API in Python
Try using the Twitter API
Try using the Twitter API
Try using the DropBox Core API in Python
Initial settings when using the foursquare API in python
Crawl the URL contained in the twitter tweet with python
Using the National Diet Library Search API in Python
Getting the arXiv API in Python
Hit the Sesami API in Python
Hit the web API in Python
Mouse operation using Windows API in Python
Get Youtube data in Python using Youtube Data API
Try hitting the YouTube API in Python
Regularly upload files to Google Drive using the Google Drive API in Python
Evernote API in Python
Search Twitter using Python
C API in Python 3
Tweet regularly with the Go language Twitter API
Get image URL using Flickr API in Python
Tips for hitting the ATND API in Python
Let's judge emotions using Emotion API in Python
Pre-process the index in Python using Solr's ScriptUpdateProcessor
Hit the Firebase Dynamic Links API in Python
Try using ChatWork API and Qiita API in Python
Sample code to get the Twitter API oauth_token and oauth_token_secret in Python 2.7
Hit Mastodon's API in Python
Upload JPG file using Google Drive API in Python
Download the file in Python
Find the difference in Python
Use Twitter API with Python
[AWS IoT] Register things in AWS IoT using the AWS IoT Python SDK
Determine the threshold using the P tile method in python
Get LEAD data using Marketo's REST API in Python
Post to Twitter using Python
Send and receive Gmail via the Gmail API using Python
Tweet with image in Python
Try to delete tweets in bulk using Twitter API
OpenVINO using Inference Engine Python API in PC environment
Post to your account using the API on Twitter
Try using the PeeringDB 2.0 API
Blender Python API in Houdini (Python 3)
Call the API with python3.
Using the LibreOffice app in Python (1) Where are the macros?
Translate using googletrans in Python
To automatically send an email with an attachment using the Gmail API in Python
Using Python mode in Processing
Continue to retrieve tweets containing specific keywords using the Streaming API in Python
A little bit from Python using the Jenkins API
Try hitting the Twitter API quickly and easily with Python
Get your heart rate from the fitbit API in Python!
Create a real-time auto-reply bot using the Twitter Streaming API
Predict gender from name using Gender API and Pykakasi in Python
Solve the Japanese problem when using the CSV module in Python.
[Python] I tried collecting data using the API of wikipedia
GUI programming in Python using Appjar
Precautions when using pit in Python