How to tweet via Python script?

tweet with python script

What do you need to install?

1. Python
2. Tweepy : Tweepy is a python library for accessing Twitter API.
3. Developer account in Twitter

Steps

1. Create a test file name test.py in your working directory.

import tweepy# Consumer keys and access tokens from twitter developer console
CONSUMER_SECRET = ‘############’
CONSUMER_KEY = ‘############’
ACCESS_SECRET = ‘#############’
ACCESS_KEY = ‘##############’
# OAuth authentication connection from
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
# Creation of the actual interface, using authentication
tweet = tweepy.API(auth)
# Write tweet here
tweet.update_status(“Hi from API” )

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store