Tweet from a Raspberry Pi

Python can send tweets using the Tweepy library and after these few steps you should be able to use it tweet from your Raspberry Pi.  Step one – download Tweepy to your Raspberry Pi with three command line statements.  In a terminal window type each command and press return.

git clone
cd tweepy
sudo python install

Once the library is installed, you can move to step two – getting the values for consumer_key, consumer_secret, access_token and access_token_secret.  It’s hard to explain this so just watch my video on YouTube:

Step three – copy this code to your favorite  editor then save it a with a descriptive name like and do not forget the .py extension.

#Import the Tweepy library
import tweepy

#Consumer keys and access tokens, used for OAuth.  You will
#need your own values and they are much longer than these examples.  #Follow the instructions from my YouTube video (link above). 
consumer_key = '1xS'
consumer_secret = 'AxD'
access_token = '3x9'
access_token_secret = 'UxR'

#OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
api.update_status('Hello World from my Raspberry Pi!')

Navigate to the directory you saved the file in and type the following command line statement in a terminal window.

sudo python

You should have tweeted “Hello World from my Raspberry Pi”.


Leave a Reply

Your email address will not be published. Required fields are marked *