1

I previously asked a question about fetching the last 100 mentions for a person via the twitter api. Now I succeeded in that, I noticed that the twitter api by default doesn't have a 'location' tag. I believe that is related to the 'search.twitter.com' result

Below you can find the code I use and the twitter search querystring. Can I add something which will force to show the location ?

Thanks in advance!

tweets = json.loads(urllib2.urlopen('http://search.twitter.com/search.json?q=BarackObama&rpp=5&include_entities=true&result_type=mixed').read())['results'][0:3]
laurens
  • 497
  • 14
  • 28

2 Answers2

1

If there are Geo Co-ordinates recorded when the tweet was sent, you will retrieve them in your search contained in the coordinates field. If it is absent, or nul then it was not recorded.

If you want to force it to only give you back tweets that have coordinates stored in them, then you can use the optional geocode parameter.

Returns tweets by users located within a given radius of the given latitude/longitude. The location is preferentially taking from the Geotagging API, but will fall back to their Twitter profile. The parameter value is specified by "latitude,longitude,radius", where radius units must be specified as either "mi" (miles) or "km" (kilometers). Note that you cannot use the near operator via the API to geocode arbitrary locations; however you can use this geocode parameter to search near geocodes directly.

Example Values: 37.781157,-122.398720,1mi

Community
  • 1
  • 1
Christian Witts
  • 11,375
  • 1
  • 33
  • 46
0

According to the Twitter documentation on search:

Location data is only included if the query includes the geocode parameter, and the user Tweeted with Geo information.

That means you need to perform a location-based search to get location data. Of course, the tweet also needs to have location data attached to it but that should be obvious.

Simeon Visser
  • 118,920
  • 18
  • 185
  • 180