2014-12-02 13 views
9

Desidero ottenere tweet di un determinato hashtag da una determinata posizione, per esempio Chennai per l'analisi dei dati. Sono davvero nuovo alle API di Twitter e tweepy. Ho trovato che l'url di ricerca sarebbe simile a questo: https://api.twitter.com/1.1/search/tweets.json?q=%23cricket&geocode=-22.912214,-43.230182,1km&lang=pt&result_type=recentCome ottenere tweet di un determinato hashtag in una posizione in un tweepy?

Come fare lo stesso in tweepy? Codice finora:

import tweepy 

ckey = "" 
csecret = "" 
atoken = "" 
asecret = "" 

OAUTH_KEYS = {'consumer_key':ckey, 'consumer_secret':csecret, 
'access_token_key':atoken, 'access_token_secret':asecret} 
auth = tweepy.OAuthHandler(OAUTH_KEYS['consumer_key'], OAUTH_KEYS['consumer_secret']) 
api = tweepy.API(auth) 

cricTweet = tweepy.Cursor(api.search, q='cricket').items(10) 

for tweet in cricTweet: 
    print tweet.created_at, tweet.text, tweet.lang 

risposta

14

È necessario utilizzare il parametro geocode in Tweepy. Utilizzando la lunga/raggio/lat dal vostro URL di ricerca, il cursore deve essere definito in questo modo:

tweepy.Cursor(api.search, q='cricket', geocode="-22.9122,-43.2302,1km").items(10) 

Vedi l'Tweepy API.searchdocumentation Per ulteriori informazioni sui parametri che è possibile includere nella vostra ricerca.

+0

Grazie mille @Luigi. Sì, funziona bene :) –

+0

Posso ottenere il numero di tweet per un determinato hashtag? Se é cosi, come? –

Problemi correlati