the_t_test_1
the_t_test_1

Reputation: 1263

How to verify Tweet with tweepy is geolocating/accepting coordinates

I am currently working on a small project where I need to send tweets through tweepy with python and include their latitude/longitude. I currently have this code which executes successfully but I'm not sure how to verify that the tweet is being successfully geocoded, and if I use a free site to look at geo-located tweets, mine never seem to show up, so is there a way I can be sure that Twitter is accepting my lat/long values and geocoding the tweet accordingly?

import tweepy

CONSUMER_KEY = 'xxxxxxxxxxxxxxxxx'
CONSUMER_SECRET = 'xxxxxxxxxxxxxxxxx'
ACCESS_KEY = 'xxxxxxxxxxxxxxxxx'
ACCESS_SECRET = 'xxxxxxxxxxxxxxxxx'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)

tweet = raw_input("Tweet text: ")

latitude = 51.51XXXXX
longitude = -0.13XXXXX

api.update_status(tweet, lat = latitude, long = longitude)

print "Sent"

It's worth noting that if I do the following search that my tweet doesn't show (and the tweet has the word 'test' in it). But then again, it might be because they don't sample everything on the free API?

results = tweepy.Cursor(api.search, q='test', geocode="51.5129418,-0.1322831,1km").items(10)

for result in results:
    print result.text

Upvotes: 1

Views: 1500

Answers (1)

the_t_test_1
the_t_test_1

Reputation: 1263

After much deliberation I've discovered the answers:

1) The simple issue that might trip people up on this - you might need to enable geolocation on your account! (Duh, woops!) ... check 'Tweet with a location' on settings (this was basically my problem).

2) When you're updating status, you only need to pass lat and long, place_id and so forth is optional/alternative way of doing location. This isn't necessary to pass your geo to Twitter - indeed, Twitter will almost certainly error if there's a technical issue with what you pass to it through Tweepy.

3) To check if your tweet is geo-ed you will see geoenabled as True in the tweet info and then you'll also see the lat and long in the json.

4) Because so few tweets are geo enabled then you should see it on most free map services because they won't hit rate limits. A good one to check is here: http://onemilliontweetmap.com/

Upvotes: 2

Related Questions