Rails 4.2.0 / Ruby 2.1.5 / Twitter 5.13.0- Twitter::Error::Forbidden: Unable to verify your credentials

156 views
Skip to first unread message

Vell

unread,
Feb 21, 2015, 3:56:55 PM2/21/15
to twitter-...@googlegroups.com
Hello all,

I am getting
Twitter::Error::Forbidden: Unable to verify your credentials
When attempting to do anything with the twitter gem inside of my rails console. I saw that this was a bug sometime ago but I don't know if I am just doing something wrong of if this bug has resurfaced again.

I am hoping someone can help me figure out what is going wrong.

Here is what I have done so far:

config/initializers/twitter.rb
$twitter = 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

Ensured that all of the environment variables show the expected keys.

Then tried to post an update to my timeline
vmcilwain [twitter_integration] $rails c
twitter
.update('check 1, 2, 3')
Twitter::Error::Forbidden: Unable to verify your credentials

I also got this same error when attempting
$twitter.user('username')

I'm wondering if anyone can provide me with any suggestions on how to debug this.

Thanks

Vell

unread,
Feb 22, 2015, 1:14:23 PM2/22/15
to twitter-...@googlegroups.com

Interestingly enough, if I put the keys directly into my initializer things work fine. So it must be something wrong with the way I have them typed in my ENV settings.

Vell

unread,
Feb 22, 2015, 4:47:01 PM2/22/15
to twitter-...@googlegroups.com
So I am still having this issue and I am not sure what to do. At the moment, I have all of my environment variables set. I can access them through the rails console but when I check twitters credentials, everything is nil.

$twitter.credentials
 
=> {:consumer_key=>nil, :consumer_secret=>nil, :token=>nil, :token_secret=>nil, :ignore_extra_keys=>true}

What can I do get twitter to set these values properly?

Thanks,


On Saturday, February 21, 2015 at 3:56:55 PM UTC-5, Vell wrote:

Vell

unread,
Feb 22, 2015, 4:51:12 PM2/22/15
to twitter-...@googlegroups.com
Well crap. I managed to exit out of my terminal by accident and when I started the terminal application back up again and check the twitter gem credentials they were set properly.  Apparently

source ~/.profile

didn't get things to work as they were supposed to?

Cori

unread,
Feb 22, 2015, 7:15:00 PM2/22/15
to twitter-...@googlegroups.com
why would you put that in your evironment ? seems security risk. how about mongodb or just include directly as you seem to have done.

anyway did you forget to export them?

Cor
--
You received this message because you are subscribed to the Google Groups "Twitter Ruby Gem" group.
To post to this group, send email to twitter-...@googlegroups.com.
Visit this group at http://groups.google.com/group/twitter-ruby-gem.

Vell

unread,
Feb 22, 2015, 9:50:04 PM2/22/15
to twitter-...@googlegroups.com


On Sunday, February 22, 2015 at 7:15:00 PM UTC-5, Cori wrote:
why would you put that in your evironment ? seems security risk. how about mongodb or just include directly as you seem to have done.

I always thought the best practice was to put them as environment variables in the shell and retrieve them using rails. If that is a risk, I certainly am up for an alternative way of doing this.

I use MYSQL and had the thought to store this info in the db but figured it would be a hassle since I am looking for this data when rails is loading up.

The issue with including it directly in my initializer is that I can't commit this info to the repository. Thats a big risk.  If I am using environment variables, I can use the variable name and store that in the repository without giving up any sensitive information for the public to see.

anyway did you forget to export them?

I did get things to export. Apparently my terminal has issues reloading my profile after I make changes to it. The only way I have gotten this to work successfully is to restart my terminal. Thats a complete pain but as long as I remember to do it, its only as painful as that.

Thanks, 
Reply all
Reply to author
Forward
0 new messages