Forum: Ruby Need help using Oauth gem for twitter

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
0faae51834740c2142efb5af4b8d8175?d=identicon&s=25 Rochit Sen (rochitsen)
on 2014-07-22 04:33
Hi All,
I have been trying to use the oauth gem with twitter. Followed the below
but i am getting "invalid or expired token". The code below is from
twitter site itself. Maybe i am passing wrong arguments?

require 'oauth'
require 'yaml'

# Exchange your oauth_token and oauth_token_secret for an AccessToken
def prepare_access_token(oauth_token, oauth_token_secret)
  consumer ="API_key", "API_Secret",
    { :site => "",
      :scheme => :header
  # now create the access token object from passed values
  token_hash = { :oauth_token => oauth_token,
                 :oauth_token_secret => oauth_token_secret
  access_token = OAuth::AccessToken.from_hash(consumer, token_hash)
  return access_token

# Exchange our oauth_token and oauth_token secret for the AccessToken
access_token = prepare_access_token("consumer_key", "consumer_secret")
# use the access token as an agent to get the home timeline
response = access_token.request(:get,
puts response.to_yaml

I have the following already provided by twitter which i am using in the
above code.

I am printing the last line (response) to yaml to see what if i have
been authorized or not.
Help much appreciated.
This topic is locked and can not be replied to.