This forum is now read-only. Please use our new forums at

Introduction to Twitter's API Forum

View Course » View Exercise

969 points
Submitted by
André Hess B
about 4 years ago

Works on codecademy, doesnt work on my computer

I don't understand. I have successfully passed step #1 which returns a 200 status code. However if I paste the same exact code and run it on my computer it returns a 401 code.

Why could this be happening?

Thanks in advance

Here's the code i'm using:

require 'rubygems'
require 'oauth'

# Change the following values to those provided on
# The consumer key identifies the application making the request.
# The access token identifies the user making the request.
consumer_key =
access_token =

# All requests will be sent to this server.
baseurl = ""

# The verify credentials endpoint returns a 200 status if
# the request is signed correctly.
address = URI("#{baseurl}/1.1/account/verify_credentials.json")

# Set up Net::HTTP to use SSL, which is required by Twitter.
http =, address.port
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER

# Build the request and authorize it with OAuth.
request = address.request_uri
request.oauth! http, consumer_key, access_token

# Issue the request and return the response.
response = http.request request
puts "The response status was #{response.code}"

0 votes


Hi Andre,

Could you paste the code? (without your keys!)


236 points
Submitted by
about 4 years ago


51a95c1ca9174cacb900006a_617271793 André Hess B about 4 years ago

HI Chloe, just edited my response with the code, replacing the keys with .... Thanks in advance

C980e95388fefa946d4c63b5b2a761bb?s=140&d=retro chloe88 about 4 years ago

Hi Andre,

The code looks fine from first inspection, do you have the 'oauth' gem installed?


C980e95388fefa946d4c63b5b2a761bb?s=140&d=retro chloe88 about 4 years ago

Actually on second thoughts I guess you do if you're getting a 401 error.
The twitter docs says your credentials were incorrect. Maybe regenerate your tokens and try again?

6c820172d5992c4857056ce78ab72e51?s=140&d=retro almost 3 years ago

I have the same problem.. any clue?