One way is to use twitter geo search API, get the place id and then perform regular search using 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 threads:
- iOS Twitter API; How to retrieve the most recent tweets within a country?
- How do I get top tweeps by country?
UPD (the 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 that helps.