使用python tweepy提取时出错401

时间:2017-09-20 04:55:43

标签: python-2.7 tweepy

我正在使用Twitter API。

我在运行此代码时遇到错误;它在每行打印401,如下所示:(see this)

from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream

access_token = "ENTER YOUR ACCESS TOKEN"
access_token_secret = "ENTER YOUR ACCESS TOKEN SECRET"

consumer_key = "ENTER YOUR API KEY"
consumer_secret = "ENTER YOUR API SECRET"

class StdOutListener(StreamListener):

    def on_data(self, data):
        print data
        return True

    def on_error(self, status):
        print status

if __name__ == '__main__':

    #This handles Twitter authetification and the connection to Twitter Streaming API
    l = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    stream = Stream(auth, l)

    #This line filter Twitter Streams to capture data by the keywords:
    stream.filter(track=['python'])

我已经输入了在Twitter帮助下生成的访问令牌和消费者密钥。 我做错了什么?

0 个答案:

没有答案