Issues authenticating


#1

Im trying to access the twitter feed for a school assignment. Unfortunately I am getting a 401 error for all requests. My code is 99% copied from the examples, yet it still fails.

@twitter_api_key = ENV[‘TWITTER_API_KEY’]
@twitter_api_secret = ENV[‘TWITTER_API_SECRET’]
@twitter_token = ENV[‘TWITTER_TOKEN’]
@twitter_token_secret = ENV[‘TWITTER_TOKEN_SECRET’]

def prepare_access_token(oauth_token = @twitter_token, oauth_token_secret = @twitter_token_secret)

source: https://dev.twitter.com/docs/auth/oauth/single-user-with-examples

consumer = OAuth::Consumer.new(“APIKey”, “APISecret”,
{ :site => “https://api.twitter.com”,
: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
end

def twitter_request

Exchange our oauth_token and oauth_token secret for the AccessToken instance.

access_token = prepare_access_token(@twitter_token, @twitter_token_secret)

use the access token as an agent to get the home timeline

response = access_token.request(:get, “https://api.twitter.com/1.1/statuses/home_timeline.json”)
return response
end

Even the curl example from the oauth test page returns a 404 error.

Any ideas? Ive verified Im using the correct token and token secrete.


#2

Yup, same here. I copied the Ruby sample and entered my own API Key and Secret. My app is set to read and write, The website and callback are entered, etc. It doesn’t work.