One way is to use the Twitter geo-search API , get the place identifier, and then do a regular search with place:place_id . Example using tweepy :
import tweepy auth = tweepy.OAuthHandler(..., ...) auth.set_access_token(..., ...) api = tweepy.API(auth) places = api.geo_search(query="USA", granularity="country") place_id = places[0].id tweets = api.search(q="place:%s" % place_id) for tweet in tweets: print tweet.text + " | " + tweet.place.name if tweet.place else "Undefined place"
Also see these topics:
- iOS Twitter API How to get the latest tweets domestically?
- How to get top tweep by country?
UPD (same example using python-twitter):
from twitter import * t = Twitter(auth=OAuth(..., ..., ..., ...)) result = t.geo.search(query="USA", granularity="country") place_id = result['result']['places'][0]['id'] result = t.search.tweets(q="place:%s" % place_id) for tweet in result['statuses']: print tweet['text'] + " | " + tweet['place']['name'] if tweet['place'] else "Undefined place"
Hope this helps.
alecxe
source share