constant uninitialized Twitter :: REST (NameError)

advertisements

So I'm getting an uninitialized constant error when trying to run this code:

require 'twitter'
require 'json'

client = Twitter::REST::Client.new do |config|
 config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
 config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
 config.access_token = ENV['TWITTER_ACCESS_TOKEN']
 config.access_token_secret = ENV['TWITTER_ACCESS_TOKEN_SECRET']
end

I took a look around and found this issue, but it doesn't seem to apply as my file name is twitterFeed.rb. Then I thought it was maybe some mismatched versioning with the gem. So I ran cleanup, but then it told me I had missing gems and it reinstalled an older version of the twitter gem. so I've got twitter (5.16.0, 4.8.1) running. Not sure exactly where to go from here to figure out why Twitter::REST is uninitialized.

Any insight would be greatly appreciated.

EDIT: After some reassessment I might have mismatch dependancies.

I get this on my console: /Users/elizabethbartscherer/.rvm/gems/ruby-2.2.1/gems/twitter-4.8.1/lib/twitter/cursor.rb:51: warning: circular argument reference - collection Faraday::Builder is now Faraday::RackBuilder.


Recommended way is to use Bundler by setting up a Gemfile, in the project directory, as follows:

source 'https://rubygems.org'

gem 'twitter'
gem 'json'

Then run bundle install.

In your twitterFeed.rb file add this to the top of the file, to look like this:

require 'rubygems'
require 'bundler/setup'

require 'twitter'
require 'json'

client = Twitter::REST::Client.new do |config|
 config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
 config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
 config.access_token = ENV['TWITTER_ACCESS_TOKEN']
 config.access_token_secret = ENV['TWITTER_ACCESS_TOKEN_SECRET']
end

Then try running your script again: ruby twitterFeed.rb