How can we get tweets from a specific country

I read a lot about this part, and what I found was to write a geocode and find tweets for example https://api.twitter.com/1.1/search/tweets.json?geocode=37.781157,-122.398720,1mi&count=10

according to what I found on the Twitter website Returns tweets by users located within a given radius of a given latitude / longitude. When using the radius modifier, no more than 1000 different "subregions" will be taken into account. Approximate Values: 37.781157, -122.398720,1mi

Question !, how can we determine or draw latitude and longitude? I tried a google map, but I only have a point, then I can add miles around this point, but this is not enough, I want the whole country to be included, is this possible?

+7
python twitter geocoding tweets
source share
1 answer

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.

+14
source share

All Articles