Tweepy流模块语言过滤器无法正常工作

时间:2015-02-17 11:18:37

标签: python api twitter tweepy

我正在尝试以下代码以法语提取推文,但它会返回英语和其他语言的推文。是否存在语法错误?

import sys
import tweepy
import config as config

consumer_key= config.CONSUMER_KEY
consumer_secret= config.CONSUMER_SECRET
access_key = config.OAUTH_TOKEN
access_secret = config.OAUTH_TOKEN_SECRET

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)



class CustomStreamListener(tweepy.StreamListener):
    def on_status(self, status):
        print status.lang
            #, status.user.location, status.user.description

    def on_error(self, status_code):
        print >> sys.stderr, 'Encountered error with status code:', status_code
        return True # Don't kill the stream

    def on_timeout(self):
        print >> sys.stderr, 'Timeout...'
        return True # Don't kill the stream

sapi = tweepy.streaming.Stream(auth, CustomStreamListener())
sapi.filter(track=["rame", "lent", "long", "beug", "beugg", "beugge", "bug"], languages = ["fr"])

2 个答案:

答案 0 :(得分:0)

尝试使用语言而不是语言 s

答案 1 :(得分:0)

有点旧的帖子,但最近我一直遇到相同的问题:关键字搜索似乎无法正常工作,即使没有关键字也似乎返回了tweet。对我有用的解决方案是使用twython和API v2 ...