ByteByByte
ByteByByte

Reputation: 393

Can't connect to Twitter API

I am creating a twitter bot, deployed on heroku, that should tweet random combinations of words at regular intervals. I set my ENV variables in heroku using

$ heroku config:set CONSUMER_KEY=xxxx CONSUMER_SECRET=xxxx  

(etc. for all of the variables)
When I try to run the bot locally by typing in the terminal

rails runner app/models/twitter_bot.rb  

I get the below error

in `on_complete': Unable to verify your credentials    (Twitter::Error::Forbidden)

I used heroku config to double-check that none of the access tokens or keys are incorrectly spelled. The asker of this similar question Twitter::Error::Forbidden - Unable to verify your credentials had an issue with quotation marks, but I used quotation marks in the twitter_bot.rb file when I created the client - see below:

client = Twitter::REST::Client.new do |config|  
  config.consumer_key = ENV["CONSUMER_KEY"]  
  config.consumer_secret = ENV["CONSUMER_SECRET"]  
  config.access_token = ENV["ACCESS_TOKEN"]  
  config.access_token_secret = ENV["ACCESS_SECRET"]  
end

Any idea why twitter can't verify my credentials? Thanks!

Upvotes: 0

Views: 160

Answers (1)

Hovercouch
Hovercouch

Reputation: 2314

heroku config:set sets the environmental variables on the heroku environment, not your local environment. Use export CONSUMER_KEY=xxxx to set environmental variables on your local machine.

Upvotes: 1

Related Questions