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

问题描述 投票:0回答:2

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

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"])
python api twitter tweepy
2个回答
1
投票

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


0
投票

尝试语言而不是语言。

© www.soinside.com 2019 - 2024. All rights reserved.