← Back to Upcase

Twitter gem requires authentication now

(Yevhen Viktorov) #1

Unable to verify your credentials

At least consumer key and secret are required, and that’s easy to fix:

  1. Register your application with twitter

  2. Put consumer key and secret into environment variables:

     export CONSUMER_KEY=123
     export CONSUMER_SECRET=secret

    or use https://github.com/bkeepers/dotenv instead

  3. Add the following to config/initializers/twitter.rb:

     Twitter.configure do |config|
       config.consumer_key = ENV['CONSUMER_KEY']
       config.consumer_secret = ENV['CONSUMER_SECRET']

Happy Testing

(Ben Orenstein) #2

Thanks for posting this!

(Patrik Bóna) #3

Please note that this is not working with newer version of twitter gem (version 5), so make sure to use 4.8.1 and it will work.

Also at first glance it looks that twitter gem API has been changed, so make sure to use version 4.8.1 if you are working on TDD workshop.

1 Like
(Acandael Acandael) #4

Hi wik, thanks for your post. I’m doing the TDD workshop and I’m stuck on this Twitter::Error::Forbidden error

Someting is not clear to me, in what file do I need to put those environment variables?

Thanks for your help,


(Acandael Acandael) #5

solved it with the .dotenv gem

(Yevhen Viktorov) #6

just type the following within your current bash session before running the specs:

export CONSUMER_KEY=123
export CONSUMER_SECRET=secret

or prepend to the actual command, e.g.:

CONSUMER_KEY=123 CONSUMER_SECRET=secret bundle exec rails s

But yeah, dotenv is a solid solution

1 Like
(Oz DiGennaro) #7

Thanks very much. Your suggestions worked for me, even rather quickly.
Ah, what a world: create a application authentication, hide it from the app, configure the gem.
Then, only then do we ge the tweets.
Oh well.

(Geoff Harcourt) #8

Second @patrikbona: The v5 of the twitter gem breaks almost everything that was working in v4.

(Louise Rains) #9

It should be noted that the consumer_key and consumer_secret are called the API key and API secret in today’s (2014-06-14) version of creating your twitter application.