This is my Python code that does not work anymore. I get this message: "The Twitter REST API v1 is no longer active. Please migrate to API v1.1".
The Python code basically uses the Python-Twitter library to ask Twitter for the status of user "x", and it then takes the last status and searches for the term "#driptwit". If found, it sends the ASCII value of 1 to the serial port (and to the Arduino). If #driptwitstop is found, it sends an ASCII value of 0. Lastly, it loops and checks the Twitter account every 15 seconds looking for changes.
As you can see, below is where you enter the keys you got from Twitter in the last step.
What should I need to change in the code to fix it?
Here is the actual code:
Enter code here ##Import Libraries`` import twitter import serial import time ##Authenticate yourself with Twitter api = twitter.Api(consumer_key='consumerkeyhere', consumer_secret='consumersecrethere', access_token_key='accesskey', access_token_secret='accesssecret') ##Set to your serial port ser = serial.Serial('COM3', 19200) ## Check serial port def checkokay(): ser.flushInput() time.sleep(3) line = ser.readline() time.sleep(3) if line == ' ': line = ser.readline() print 'here' ## Welcome message print 'Welcome To Drip Twit!' print 'Making Coffee..' def driptwit(): status = [ ] x = 0 status = api.GetUserTimeline('X') ##Grab latest statuses checkIt = [s.text for s in status] ##Put status in an array drip = checkIt.split() ##Split first tweet into words ## Check for match and write to serial if match if drip == '#driptwit': print 'Tweet received, making coffee' ser.write('1') elif drip == '#driptwitstop': ##Break if done ser.write('0') print 'Stopped, awaiting instructions.' else: ser.write('0') print 'Awaiting tweet' while 1: driptwit() ## Call driptwit function time.sleep(15) ## Sleep for 15 seconds to avoid rate limiting.
The Twitter API that your Twitter module is based off of has been discontinued. You'll need to refer to an updated Twitter package that'll use the 1.1 API instead.
Like @Madbreaks said: You might be able to write your own with some of the solutions presented in Stack Overflow question Authentication for new Twitter API 1.1.
You'll have to write your own API using their 1.1 or find another package that supports 1.1 already. The important part of the error message is:
u'The Twitter REST API v1 is no longer active. Please migrate to API v1.1. dev.twitter.com/docs/api/1.1/overview.'