Error with Ruby Twitter API

Error with Ruby Twitter API

You are doing it the "old" way. Starting in Version 5, global configuration is not longer available. So, basically you need to pass the config parameters when you initialize a client.

For example:

client = Twitter::REST::Client.new do |config|
config.consumer_key = "YOUR_CONSUMER_KEY"
config.consumer_secret = "YOUR_CONSUMER_SECRET"
config.access_token = "YOUR_ACCESS_TOKEN"
config.access_token_secret = "YOUR_ACCESS_SECRET"
end

And then just use that client to do queries, such as:

client.sample do |tweet|
puts tweet.text
end

For more information just refer to Sferik's Twitter Gem

OAuth error in using twitter API v2 for posting a tweet

You need to insert

require 'oauth/request_proxy/typhoeus_request'

and your code may complete task you desire.
Other lines looks good to me!


In oauth/request_proxy.rb, oauth library check class of request object.

https://github.com/oauth-xx/oauth-ruby/blob/master/lib/oauth/request_proxy.rb

return request if request.is_a?(OAuth::RequestProxy::Base)

klass = available_proxies[request.class]

# Search for possible superclass matches.
if klass.nil?
request_parent = available_proxies.keys.find { |rc| request.is_a?(rc) }
klass = available_proxies[request_parent]
end

raise UnknownRequestType, request.class.to_s unless klass

By requiring 'oauth/request_proxy/typhoeus_request', Typhoeus::Request inherits OAuth::RequestProxy::Base and raising UnknownRequestType error can be avoided.

https://github.com/oauth-xx/oauth-ruby/blob/master/lib/oauth/request_proxy/typhoeus_request.rb

Error on Heroku when using Twitter API

The solution was that I needed to add my Twitter API credentials into Heroku.

heroku config:add TWITTER_CONSUMER_KEY=<<Your twitter consumer key>>
heroku config:add TWITTER_CONSUMER_SECRET=<<Your twitter consumer secret>>

Sources:

  • https://devcenter.heroku.com/articles/config-vars
  • https://github.com/mortardata/twitter-gardenhose/blob/master/README.md


Related Topics



Leave a reply



Submit