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

Introduction to Twitter's API Forum

View Course » View Exercise

2126 points
Submitted by
Nicholas Hazel
almost 4 years ago

Worked before, now it doesn't. Help?

I see no flaws with code. But it doesn't pass...

require 'rubygems'
require 'oauth'
require 'json'
baseurl = ""
path    = "/1.1/statuses/user_timeline.json"
query   = URI.encode_www_form(
    "screen_name" => "twitterapi",
    "count" => 5,
address = URI("#{baseurl}#{path}?#{query}")
request = address.request_uri
def print_timeline(tweets)
 tweets.each{ |tweet|
   puts tweet['text']
http             =, address.port
http.use_ssl     = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
consumer_key ||= "ENTER IN EXERCISE 1", ""
access_token ||= "ENTER IN EXERCISE 1", ""
request.oauth! http, consumer_key, access_token
response = http.request request
tweets = nil
if response.code == '200' then
  tweets = JSON.parse(response.body)

1 vote


I found the trick was to go back to 1/5 and refresh the credentials by simply clicking "save & submit" than jumping back to 4/5. And also might want to change

"count" => 5,


"count" => 10,

other wise it will throw up another error.


322 points
Submitted by
over 3 years ago

0 votes



Oops, try again. The response code should be '200' but you received '401'. Double check the credentials you passed to the OAuth library. You may need to go back and execute your answer for exercise 1 in order to load the correct credentials. 

2126 points
Submitted by
Nicholas Hazel
almost 4 years ago


512d3f8f7df8cbb462001736_165830919 Nicholas Hazel almost 4 years ago

Yes, I have a twitter account and am familiar with the creds.

9e766e4880d9a79fd1244c1b04dc31fe?s=140&d=retro Nishanth over 3 years ago

Going back and resubmitting the Exercise 1 code helped. The Twitter API times out on your creds after a while.

0 votes


Newbie here, but what I figured out is that you have to allow certain permissions in the Twitter app. I changed the Settings to "Read and Write" and checked the box at the bottom to "Allow this application to be used to sign into Twitter."

Also, I noticed when I kept checking a few times, that it stopped working until I logged back into my account. Then it started working again.

This is just what I found through trial and error. Hope someone finds this helpful.

595 points
Submitted by
over 3 years ago

1 Comment

512d3f8f7df8cbb462001736_165830919 Nicholas Hazel over 3 years ago

Yeah, I definitely passed based on passing full credentials to the API call (very bad idea). I suppose the jist of it is that you should understand the concept. I've goofed with enough APIs to know that they are liquid (ever-changing) and you simply need to read documentation, as the rate they evolve is much faster than some course or textbook could document. My advice is to test working implementations and view source code to see what's actually occurring.