Introduction: Tweeting With Raspberry Pi

Picture of 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

Picture of 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

Picture of Insert All Informations and Create an App - Fill the Form

Step 3:

Picture of

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!!!

Picture of Your Raspberry Pi Is Tweeting!!!

Your Raspberry Pi will tweet!

That's all folks! Happy Hacking!

Comments

joelm145 (author)2017-02-27

Hi,
How can I connect a Blackberry Bold Q10 nano-keyboard to a raspberry?
I want to make my raspberry portable console with a nano-keyboard of a Blackberry Bold Q10 but i don't know how to connect it XD

About This Instructable

3,930views

52favorites

License:

Bio: ​M.Sc. in Electrical Engineering in Rochester Institute of Technology at USA and CMO of Embarcados.
More by tpfslima:Tweeting With Raspberry PiTweeting DoorbellQualcomm Dragonboard 410C with Grove Starter Kit - First Steps
Add instructable to: