Domanda

Ho alcuni problemi con l'API tweepy.

Sto solo cercando di scrivere una piccola applicazione che mi viene un flusso di status di un utente (minerale di più), ma uno sarebbe bene per cominciare; -)

ora: il mio codice è così:

    def main():
       config = ConfigParser.ConfigParser()
       config.read('twitter.cfg')

       username = config.get('Twitter', 'username')
       password = config.get('Twitter', 'password') 
           listener = StreamWatcherListener()

       stream = tweepy.Stream(username, password, listener, timeout=None)
       stream.filter('132897940')

in StreamWatcherListener Ho un metodo "on_status" che stampa il testo di uno status, ogni volta che un nuovo arriva (tutto sembra funzionare, quando provo stream.sample () al posto di stream.filter ())

il dato ID è il mio Testaccount, così ogni volta che tweet dovrei ottenere qualche risposta nella console .... ma non succede nulla.

quando provo

curl -d @following http://stream.twitter.com/1/statuses/filter.json -uAnyTwitterUser:Password

nel terminale, come ho potuto trovare nella API di Twitter, tutto funziona bene.

Quindi forse faccio uso sbagliato del filtro () - Metodo

?

qualche suggerimento?

-Andy

È stato utile?

Soluzione

L'ho trovato io stesso

il metodo stream.filter() richiede un array

così ho dovuto codice

stream.filter(['1234567'])

et voilà

Altri suggerimenti

class TweetListener(StreamListener):
    def on_status(self,status):           
        print "TWEET ARRIVED!!!"
        print "Tweet Text : %s" % status.text
        print "Author's name : %s" % status.author.screen_name
        print "Time of creation : %s" % status.created_at
        print "Source of Tweet : %s" % status.source    
        time.sleep(10)       
        return True

    def on_error(self, status):        
       print status
       if status == 420:
            print "Too soon reconnected, Exiting!!"
            return False
        sys.exit()

def search_tweets():
    twitterStream = Stream(connect().auth, TweetListener())        
    twitterStream.filter(track=['Cricket','Maths','Army','Sports'],languages = ["en"],async=True)

Qui ho utilizzato il parametro asincrono, che gira ogni flusso su un thread diverso. Fare riferimento questo link per la documentazione o più dettagli.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top