0

I'm new to Rails and developing in general and am trying to use the Twitter gem to search for tweets by location and keywords in my Rails app. Following the documentation at http://www.rubydoc.info/gems/twitter I have been able to figure out how to search for tweets by keyword (in my case #restaurant) but not filter this by my user's location.

I am currently trying the following:

In my controller

@search = client.search("#restaurant", result_type "recent", geocode: "#{@lat}, #{@lon}, #{@radius}mi")

In my view:

<% @search.take(3).each do |tweet| %> <% tweet.text %> <% end %>

If the geocode parameter is taken out I get 3 tweets with "#restaurant", but with the geocode nothing is returned. Is there a problem with my code?

As I am so new to programming, I could be approaching this problem completely wrong and I'm also open to any alternative approaches.

  • 1
    are you sure there should be results with this geocode? when you're debugging you always need to make sure that your successful case actually is successful. If you have 3 results without geocode it is likely that with geocode there might be none. Maybe tweet yourself ... – Lukasz Muzyka Mar 03 '17 at 03:03
  • I understand what you're saying and I should have made it clearer that I've tried different geolocations (fixed ones and also based on the user IP address) and distances. Without the gelocation I can get all tweets that contain "#restaurant" so it's definitely the gelocation thing that's the issue. I tried your advice about tweeting myself - no luck! Nice idea though. – user8277633 Mar 03 '17 at 12:56

1 Answers1

0

This might sound a little dump but your Geocode is in the middle of Peru as far as I can tell and 100miles might be too small of a radius. How about increase the miles (10000 miles) and try again.

I took that advice from this post: Twitter Gem with multiple search options

Community
  • 1
  • 1
Alexander Luna
  • 5,261
  • 4
  • 30
  • 36
  • Thanks for your response. The actual geolocation wasn't important so I changed it to geocode: "51.5007, 0.1246, 100mi" which corresponds to Big Ben in London. Still no luck. I've tried messing around with the radius as well but I think there is a maximum radius so I'm not sure 10,000 miles would work. – user8277633 Mar 03 '17 at 10:53