How to post a tweet using Python?

/ #Python


Learn how easy it is to connect to your twitter account and post a tweet using Python

Installing the software we need

We don't need a lot, but we need one package. Let's install a package called "Tweepy".

$ pip install tweeps

Example

import tweepy

# Authenticate
auth = tweepy.OAuthHandler("CONSUMER_KEY", "YOUR_CONSUMER_SECRET")
auth.set_access_token("ACCESS_TOKEN", "YOUR_ACCESS_TOKEN_SECRET")

# Create API object
api = tweepy.API(auth)

# Create a tweet
api.update_status("Hello from my Python script")

To get the token and secret, you need to log in to Twitter and create a new app there.

Comments

No comments yet...

Add comment

Info

Please log in to comment!

Newsletter

Subscribe to my weekly newsletter. One time per week I will send you a short summary of the tutorials I have posted in the past week.