Problem with GEO activated and without Lat or Long in Tweet's with Tweepy and Python

4

I think in the question I said everything.

I use Python 3.5, Tweepy and after a search (search) of tweets through a keyword, I see that many have the GEO active but I can not access Lat and Lng using Tweepy.

Does anyone know where these fields are and what would be the exact syntax to access if they existed?

    
asked by papabomay 21.02.2016 в 17:41
source

1 answer

2

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]
    
answered by 21.02.2016 / 18:31
source