sferik / twitter-ruby

A Ruby interface to the Twitter API.
http://www.rubydoc.info/gems/twitter
MIT License
4.58k stars 1.31k forks source link

Streaming Client - Twitter::Error::Unauthorized #633

Closed jordan-wright closed 9 years ago

jordan-wright commented 9 years ago

I'm trying to use Logstash's twitter input, which utilizes this library to connect to the streaming API. I am getting a Twitter::Error::Unauthorized error, even though I am sure I am using valid credentials.

Here's a stack trace:

  Error:
  Exception: Twitter::Error::Unauthorized
  Stack: /root/logstash-master/vendor/bundle/jruby/1.9/gems/twitter-5.13.0/lib/twitter/streaming/response.rb:21:in `on_headers_complete'
org/ruby_http_parser/RubyHttpParser.java:370:in `<<'
/root/logstash-master/vendor/bundle/jruby/1.9/gems/twitter-5.13.0/lib/twitter/streaming/response.rb:16:in `<<'
/root/logstash-master/vendor/bundle/jruby/1.9/gems/twitter-5.13.0/lib/twitter/streaming/connection.rb:22:in `stream'
/root/logstash-master/vendor/bundle/jruby/1.9/gems/twitter-5.13.0/lib/twitter/streaming/client.rb:118:in `request'
/root/logstash-master/vendor/bundle/jruby/1.9/gems/twitter-5.13.0/lib/twitter/streaming/client.rb:37:in `filter'
/root/logstash-master/lib/logstash/inputs/twitter.rb:67:in `run'
/root/logstash-master/lib/logstash/pipeline.rb:171:in `inputworker'
/root/logstash-master/lib/logstash/pipeline.rb:165:in `start_input' {:level=>:error, :file=>"logstash/pipeline.rb", :line=>"176"}

Here's a snippet of the affected code:

def register
    require "twitter"
    @client = Twitter::Streaming::Client.new do |c|
      c.consumer_key = @consumer_key
      c.consumer_secret = @consumer_secret.value
      c.access_token = @oauth_token
      c.access_token_secret = @oauth_token_secret.value
    end
  end

  public
  def run(queue)
    @logger.info("Starting twitter tracking", :keywords => @keywords)
    @client.filter(:track => @keywords.join(",")) do |tweet|
      @logger.info? && @logger.info("Got tweet", :user => tweet.user.screen_name, :text => tweet.text)

I have used Twitter's OAuth Tool to check the validity of my credentials and everything checks out fine. Do you know of any issues in this library that might be causing this? Here are the gems I have installed (I wasn't sure which were significant, so I included all used by Logstash):

activesupport-4.1.8
addressable-2.3.6
axiom-types-0.1.1
backports-3.6.4
buftok-0.2.0
builder-3.2.2
cabin-0.6.1
ci_reporter-1.9.3
clamp-0.6.3
coderay-1.1.0
coercible-1.0.0
descendants_tracker-0.0.4
diff-lcs-1.2.5
equalizer-0.0.9
faraday-0.9.0
ffi-1.9.6-java
ftw-0.0.42
gem_publisher-1.5.0
http-0.6.3
http_parser.rb-0.6.0-java
i18n-0.6.9
ice_nine-0.11.1
insist-1.0.0
jar-dependencies-0.1.7
jrjackson-0.2.7
jruby-httpclient-1.1.1-java
json-1.8.1-java
logstash-devutils-0.0.5-java
mail-2.5.3
maven-tools-1.0.7
memoizable-0.4.2
metaclass-0.0.4
method_source-0.8.2
mime-types-1.25.1
minitar-0.5.4
minitest-5.4.3
mocha-1.1.0
msgpack-jruby-1.4.0-java
multipart-post-2.0.0
naught-1.0.0
polyglot-0.3.5
pry-0.10.1-java
rack-1.5.2
rack-protection-1.5.3
rake-10.4.2
rspec-2.14.1
rspec-core-2.14.8
rspec-expectations-2.14.5
rspec-mocks-2.14.6
ruby-maven-3.1.1.0.8
ruby-maven-libs-3.1.1
rumbster-1.1.1
shoulda-3.5.0
shoulda-context-1.2.1
shoulda-matchers-2.7.0
simple_oauth-0.3.0
sinatra-1.4.5
slop-3.6.0
spoon-0.0.4
stud-0.0.18
thread_safe-0.3.4-java
tilt-1.4.1
treetop-1.4.15
twitter-5.13.0
tzinfo-1.2.2
virtus-1.0.3
jordan-wright commented 9 years ago

Turns out, the date on my machine was wrong, causing the 401.

That's what my life is, now :disappointed:

Keep up the great library!

MartinRogalla commented 9 years ago

Thank you so much! This was exactly my problem.:smiley:

Dawil commented 9 years ago

Thanks from me too! I'm not sure if I would have caught that.