Introduction: Tweeting With Raspberry Pi
In this instructable, I will explain how to make your Raspberry Pi tweet!
To run this tutorial you'll need:
- Raspberry Pi - I'm using Rasp 2B
- USB Mouse
- USB Keyboard
- Monitor
- HDMI Cable
- USB power supply for Raspberry
- Internet
I based this tutorial in the following texts:
https://www.instructables.com/id/Tweeting-Doorbell/
https://www.raspberrypi.org/learning/getting-start...
http://pythoncentral.io/how-to-use-the-twython-twi...
https://gofedora.com/how-to-install-use-twython-py...
http://www.makeuseof.com/tag/how-to-build-a-raspbe...
http://stackoverflow.com/questions/17309288/import...
https://pypi.python.org/pypi/twython
https://www.instructables.com/id/How-to-Send-Tweets...
So, let's start!
Step 1: Creat an App at Your Twitter Account
Go to your twitter account. You'll need the following parameters to make your Rasp Pi Tweet, that you'll get from this app
- Consumer Key (API key)
- Consumer Secret (API Secret)
- Access Token
- Access Token Secret
Step 2: Insert All Informations and Create an App - Fill the Form
Step 3:
Access Keys and Access Tokens tab in your app, that you just created.
Get all the tokens and create a file in Raspberry Pi, inside your working folder, called keys.py with all your information in it.
consumer_key = "aaaaaaaaa" consumer_secret = "bbbbbbbbbbb" access_token = "cccccccccc" access_token_secret = "dddddddddd"
Step 4: Install Twython in Your Raspberry Pi
Open a terminal in Raspberry Pi, choose a working folder and run the following commands to install Twython, a python package that is required for this experiment.
sudo apt-get update sudo apt-get upgrade sudo apt-get install python-setuptools sudo easy_install pip sudo pip install twython sudo pip install requests sudo pip install requests-oauthlib
Step 5:
Open a file and your working directory in Pi and rename it to twitter.py.
import sys from twython import Twython from keys import ( consumer_key, consumer_secret, access_token, access_token_secret ) twitter = Twython( consumer_key, consumer_secret, access_token, access_token_secret ) message = "Meu primeiro tweet - a conta do tpfslima foi invadida poruma plaquinha Raspberry Pi bem espertinha!" twitter.update_status(status=message)print("Sua mensagem foi twittada com sucesso: %s " % message)
Save it and run it using
python twitter.py
Step 6: Your Raspberry Pi Is Tweeting!!!
Your Raspberry Pi will tweet!
That's all folks! Happy Hacking!