首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Twython 401错误

Twython 401错误
EN

Stack Overflow用户
提问于 2016-12-07 15:53:02
回答 1查看 197关注 0票数 0

为什么这段代码总是返回401错误?我从这里克隆了它"https://github.com/purplewove/social-media-apis“来测试twython的功能,但是尽管我有我的twitter密钥和秘密,我只得到了很多401而不是真正的tweet。

我习惯了Python3.5,但在3.X或2.X中运行时没有任何客户端错误。我使用Anaconda包,因为已经成功执行了"pip install twython“。

代码如下(源码原样):

代码语言:javascript
复制
'''
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)
EN

回答 1

Stack Overflow用户

发布于 2016-12-30 00:57:55

我重新生成了密钥,它起作用了。您需要在每次更换机器时执行此操作。不确定是什么问题...

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41012042

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档