我正在尝试让我的覆盆子pi使用某个标签在特定用户的Twitter上观看Twitter。当它看到符合条件的推文时,它应该拍照,然后将图片发回给用户。它一直工作到应该上传图片,然后我得到一个“Twitter API返回401(未经授权)”。我不知道它为什么返回401,因为凭证早于脚本的流部分工作。任何帮助将不胜感激!
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')
答案 0 :(得分:0)
我创建了新的oauth秘密并解决了这个问题。但是,现在它返回:
“TwythonError:Twitter API返回403(禁止),丢失或无效的url参数。”