0

I am trying to get my raspberry pi to watch twitter for tweets at a certain user using a certain hashtag. When it sees a tweet that meets the criteria, it should take a picture and then tweet the picture back at the user. It works up until the point where it should upload the picture, and then I get a "Twitter API returned a 401 (Unauthorized)". I don't know why it is returning a 401 because the credentials work earlier for the streaming portion of the script. Any help would be much appreciated!

from twython import Twython
from twython import TwythonStreamer
import sys
import os

APP_KEY = 'X'
APP_SECRET = 'X'
OAUTH_TOKEN = 'X'
OAUTH_TOKEN_SECRET = 'X'

def takePicture(id_str, screen_name):
    os.system('raspistill -o ' + str(id_str) + '_@' + str(screen_name) + '.png -t 3000 -w 1080 -h 720 -n -vf')

def photo(id_str, screen_name):
    open('/home/pi/' + str(id_str) + '_@' + str(screen_name) + '.png', 'rb')

def uppic(screen_name):
    twitter.update_status_with_media(status='@' + str(screen_name) + ' is super awesome!', media=photo)

class MyStreamer(TwythonStreamer):
    def on_success(self, data):
        print data['user']['screen_name'].encode('utf-8')
        print data['id_str'].encode('utf-8')
        print data['text'].encode('utf-8')
        takePicture(data['id_str'], data['user']['screen_name'])
        photo(data['id_str'], data['user']['screen_name'])
        uppic(data['user']['screen_name'])

    def on_error(elf, status_code, data):
        print status_code

stream = MyStreamer(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

stream.statuses.filter(track='#hashtag @user')

1 Answers1

0

I created new oauth secrets and that resolved the problem. However, now it returns:

"TwythonError: Twitter API returned a 403 (Forbidden), Missing or invalid url parameter."