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 https://github.com/tweepy/tweepy.git cd tweepy sudo python setup.py 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: https://youtu.be/xEQYbT1gpxo
Step three – copy this code to your favorite editor then save it a with a descriptive name like HelloWorld.py 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 HelloWorld.py
You should have tweeted “Hello World from my Raspberry Pi”.