I've been messing around with the twitter rails API and I'm having trouble getting a tweet's location. This always seems to fail and not return anything. I've also tried doing tweet.coordinates but it doesn't seem to work.
tweets = client.user_timeline("gems")
puts "size : #{tweets.size}"
tweets.each do |tweet|
if(tweet.place)
puts tweet.place.attributes
end
end
I'm using the following twitter gem. https://github.com/sferik/twitter
EDIT:
tweets = client.search("a", geocode: "40.7128,-74.0059,50mi").take(100)
tweets.each do |tweet|
if tweet.place?
puts tweet.place.full_name
elsif tweet.geo?
puts "geofound"
elsif tweet.user.location?
puts tweet.user.location
end
So I tried the above code looking for tweets that have geocodes, but it seems that none of them have a place or geo field and it always returns the tweet.user.location, but that's not very accurate. The output just has a lot of New York's, but also a bunch from other cities as well so I don't really know how Twitter got those queries when the other cities don't exist/are far away from NY. Am I missing another location field? I also noted that the number of outputs doesn't equal the size of the tweet array.
Here's an example output
puts tweet.inspecton the first line of the loop body to see if the tweet is present. - mahemofftweet.inspectand paste the result along with the question? - Pramod