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
Run a Command Line with Custom Environment
Ruby Conditional-Assignment and Private Methods
How to Set Environment Variable Using Chef
How to Render a String as an Erb File
Ruby Map Method Syntax Question
Is Ruby's Stdlib Logger Class Thread-Safe
Your Ruby Version Is 2.2.4, But Your Gemfile Specified 2.3.0
How to Handle Utf-8 Email Headers (Like Subject:) Using Ruby
Sorting a Hash in Ruby by Its Value First Then Its Key
Write Array of Radix-2 Numeric Strings to Binary File in Ruby
Where to Put a Before_Filter Shared Between Multiple Controllers
Is Getting Converted as "\U0092" by Nokogiri in Ruby on Rails
Rvm System-Wide Install Script Url Broken -- What Is Replacement
Listing Directories at a Given Level in Amazon S3