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/
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-setuptools
sudo easy_install pip
sudo pip install twythonIn 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.
Navigate to the Raspberry Pi home directory
sudo git clone https://github.com/mvartani76/RPi-Twitter-GetUserTimeline-Tutorial-PythonCopy 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)sudo python rpi-read-tweet.pyNote 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.py401 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"


