Skip to content

mvartani76/RPi-Twitter-GetUserTimeline-Tutorial-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RPi-Twitter-GetUserTimeline-Tutorial-Python

Some simple demo code that shows use of get_user_timeline() Twitter API function used to control RPi

This code borrows some material from http://www.makeuseof.com/tag/how-to-build-a-raspberry-pi-twitter-bot/

Install Twython

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-setuptools
sudo easy_install pip
sudo pip install twython

Register Twitter App

In order to use the Twitter API – that is, the REST interface that we’ll use to post new Tweets and generally interact with Twitter outisde of the twitter website – we’ll need to register a new app.

Do that from this link, https://dev.twitter.com/apps/new – you needn’t specify a callback URL, and just make up a website if you want.

You’ll see something resembling this once you’re done – these keys are unique to you.

By default, the app is set to read-only, so we won’t be able to publish tweets without changing that to Read and Write. Go to the Settings tab and change the Application type.

Once saved, head back to the Details tab and click the button at the bottom to create an OAuth access token – this gives your application access to your own Twitter account. Refresh, and leave the page open for later – we’ll need to copy paste some of those keys in a minute.

Get Code from GitHub

Navigate to the Raspberry Pi home directory

sudo git clone https://github.com/mvartani76/RPi-Twitter-GetUserTimeline-Tutorial-Python

Update Source with Twitter Credentials

Copy the generated keys from the previous step into the following variables mentioned below.

#!/usr/bin/env python
import sys
from twython import Twython
CONSUMER_KEY = '***************YOUR DATA*****************'
CONSUMER_SECRET = '***************YOUR DATA*****************'
ACCESS_KEY = '***************YOUR DATA*****************'
ACCESS_SECRET = '***************YOUR DATA*****************'

api = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)

Run Code

sudo python rpi-read-tweet.py

Note that GPIO 11 is altered via tweets, "RPI ON" (HIGH) and "RPI OFF" (LOW).

Or the Xbee version of the code...

sudo python rpi-read-tweet-xbee.py

Common Error Messages

401 Error Unauthorized Twitter Page -- Make sure that the time on the server and client are synchronized. This became an issue for me when I traveled from Detroit to San Jose.

To manually change the date and time to synchronize, try the following

sudo date -s "Tues Dec  10 11:14:26 PST 2013"

About

Some simple demo code that shows use of get_user_timeline() Twitter API function used to control RPi

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages