First of all, it should be noted that the field geo
of the Tweets API has been deprecated:
Deprecated. Nullable. Use the "coordinates" field instead. Discussion
The correct thing is to use the field coordinates
:
The longitude and latitude of the Tweet's location, as an collection in the form of [longitude, latitude].
Example:
"coordinates":[-97.51087576,35.46500176]
Keep in mind that not all tweets have geolocation, so you should validate the field beforehand. I leave you a small example that I just made:
# -*- coding: utf-8 -*-
import tweepy
# Tus credenciales
ACCESS_TOKEN = 'xxxxxxxxxxxxxxxxxxxxxx'
ACCESS_TOKEN_SECRET = 'xxxxxxxxxxxxxxxxxxxxxx'
CONSUMER_KEY = 'xxxxxxxxxxxxxxxxxxxxxx'
CONSUMER_SECRET = 'xxxxxxxxxxxxxxxxxxxxxx'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
public_tweets = api.search('#python')
for tweet in public_tweets:
if tweet.coordinates:
print tweet.coordinates
print tweet.coordinates['coordinates']
An example output would be:
{u'type': u'Point', u'coordinates': [106.86663792, -6.16509361]}
[106.86663792, -6.16509361]