I am getting an error with a Ruby script using the 'twitter' gem. The part of my script that is producing the error is
require 'twitter'
require 'net/http'
require 'json'
#### Get your twitter keys & secrets:
#### https://dev.twitter.com/docs/auth/tokens-devtwittercom
Twitter.configure do |config|
config.consumer_key = 'xxxxxxx'
config.consumer_secret = 'xxxxxxx'
config.oauth_token = 'xxxxxx'
config.oauth_token_secret = 'xxxxxxx'
end
The error says undefined method 'configure' for Twitter:Module (NoMethodError)
However the 'twitter' and 'json' gems are both in my gemfile so I'm not sure why this method would be undefined.
Twitter was at one time thought to be the largest Ruby on Rails shop in the world, and has made a substantial investment in its Ruby stack, going as far as developing its own generational garbage collector for Ruby called Kiji, which, unlike the standard Ruby collector, divides objects into generations and, on most ...
You can do application-only authentication using your apps consumer API keys, or by using a App only Access Token (Bearer Token). This means that the only requests you can make to a Twitter API must not require an authenticated user.
In Authorization tab, select OAuth 1.0. Enter your consumer key, consumer secret, access token and access token secret. Enable “Add params to header” and “Auto add parameters” Send the request.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With