2016-12-07 15 views
0

このコードが常に401エラーを返す理由は何ですか?私はtwythonの機能をテストするためにここに "https://github.com/purplewove/social-media-apis"からクローンを作成しましたが、私のtwitterキーと秘密はありますが、実際のつぶやきではなくたくさんの401を取得しています。Twython 401エラー

私はPython 3.5に慣れていますが、これは3.Xまたは2.Xでクライアント側のエラーなしで実行されているようです。私はAnacondaパッケージを使用しています。「pip install twython」が正常に終了しました。

コードは以下の通り(変わらずソースから)です:

''' 
social-media-apis 
================= 

currently just a bit of code for keyword searches using twython 

to use, make sure twython is installed and then type: 
python filter_terms.py [consumer_key] [consumer_secret] [access_token_key] [access_token_secret] [search_term] 

and the script will dump the text from all tweets gleaned from the streaming api containing the search term to standard output. 

find consumer_key, consumer_secret, access_token_key, access_token_secret here: dev.twitter.com/apps 
''' 

#filter_terms.py 

from Stream import Stream 
import sys 


app_key = sys.argv[1] 
app_secret = sys.argv[2] 
oauth_token = sys.argv[3] 
oauth_token_secret = sys.argv[4] 
terms = sys.argv[5:] 


stream = Stream(app_key, app_secret, oauth_token, oauth_token_secret) 
stream.filter_terms(terms) 


#Stream.py 

from MyStreamer import MyStreamer 

class Stream(): 
    def __init__(self, app_key, app_secret, oauth_token, oauth_token_secret): 
     self.streamer = MyStreamer(app_key, app_secret, oauth_token, oauth_token_secret) 

    def filter_terms(self, terms): 
     self.streamer.filter_terms(terms)  

#MyStreamer.py 

from twython import TwythonStreamer 
import sqlite3 
import sys 
import datetime 

class MyStreamer(TwythonStreamer): 
    '''a simple streamer that prints the text of a tweet to standard output''' 
    def __init__(self, app_key, app_secret, oauth_token, oauth_token_secret): 
     TwythonStreamer.__init__(self, app_key, app_secret, oauth_token, oauth_token_secret) 

    def on_success(self, data): 
     if 'text' in data: 
      print (data['text']) 

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

    def filter_terms(self, terms): 
     '.'.join(terms) 
     self.statuses.filter(track = terms) 
+0

あなたのアプリがhttps://apps.twitter.comで停止または制限されていないことを確認しましたか? –

答えて

0

私は、キーを再生成し、それが働きました。マシンを変更するたびにこれを行う必要があります。問題が何だったのかわからない...