Search code examples
pythonapitwittergeolocationstreaming

Twitter API Streaming by Locatons


I'm using a Python's Twitter API implementation, TwitterAPI.

I'm trying get tweets from a specific city (São Paulo), in the Twitter Advanced Search(https://twitter.com/search-advanced) website is easy, but when I try to do it using streaming, never returns any tweet. (I know search-advanced is complete different from twitter streaming API)

enter image description here

Like follow the documentation I get the southwest coordinate first, and northeast after. https://dev.twitter.com/streaming/overview/request-parameters#locations

#!/usr/bin/python

import pprint from TwitterAPI import TwitterAPI

pp = pprint.PrettyPrinter(depth=6)

api = TwitterAPI(CONSUMER_KEY,
                 CONSUMER_SECRET,
                 ACCESS_TOKEN_KEY,
                 ACCESS_TOKEN_SECRET)

r = api.request('statuses/filter', {'locations':'-23.984524,-46.885064,-23.393466,-46.479943'})

for item in r:
    pp.pprint(item)

But I never got any tweet, what I'am doing wrong ?


Solution

  • You have the latitudes and longitudes reversed. Try:

    r = api.request('statuses/filter', {'locations':'-46.885064,-23.984524,-46.479943,-23.393466'})
    

    The locations parameter takes longitude/latitude pairs.