Search code examples
ruby-on-railstwittertwitter-gem

Using the twitter gem to retrieve all tweets containing a certain term, in a certain time window


I've been having a tough time finding info on this since the tweet count was restricted. I've started with this to get tweets in the last two week window:

    client.search(
        "to:justinbieber marry me",
        result_type: "recent",
        since: (Time.now-(2*7*24*60*60)).to_s
    ).each do |tweet|
        puts tweet.text
    end

This doesn't work. And if it did would only return a certain number of tweets because of the limit. I want all the tweets meeting my query in the time window. Any suggestions? Thank you.


Solution

  • It's your since parameters that is incorrect. You are passing a Time and twitter expects a date only. It works fine if you do something like:

    client.search(
      "to:justinbieber marry me",
      result_type: "recent",
      since: (Time.now-2.weeks).to_date
    ).each do |tweet|
      puts tweet.text
    end