如何在ruby中过滤基于位置的推文?

时间:2015-04-21 14:33:43

标签: ruby-on-rails ruby twitter geolocation

我使用的是一个简单的机器人,它是基于关键字的最喜欢的推文。我只想从特定位置收到喜欢的推文。知道如何在ruby中做到这一点?如果在ruby中不可能,我可以使用其他语言。感谢

我的代码:

require 'twitter' #gem install twitter

while true
begin
    config = {
        consumer_key: 
        consumer_secret:
        access_token: 
        access_token_secret:
    }

    rClient = Twitter::REST::Client.new config
    sClient = Twitter::Streaming::Client.new(config)

    # topics to watch
    topics = ['star wars']
    sClient.filter(:track => topics.join(',')) do |tweet|
        if tweet.is_a?(Twitter::Tweet)
          puts tweet.text 
          rClient.fav tweet
        end
    end
rescue Exception => e
    puts 'error, waiting for 5s: ' + e.class.to_s
    sleep 5
end
end

我尝试添加这些行,但它不起作用(对于NYC lat / long):

    @Geo = Twitter::Geo.new(coordinates: [22.2798024,114.149884])
    sClient.filter(:track => topics.join(','), :Geo => Tweet.Geo('40.7033127,-73.979681')) do |tweet|

1 个答案:

答案 0 :(得分:1)

要根据位置进行过滤,您需要哈希中的location参数。

所以,这就是你的过滤函数调用应该是什么样的

sClient.filter(:track => topics.join(','), :locations => "40.7033127,-73.979681") do |tweet|

多数民众赞成,你很高兴。我在documentationexample中找到了它。