Introduction to Twitter's API Forum

No room for error in 3. Reading a Tweet

So this drove me almost mad: in the def print method, I added puts JSON.pretty_generate(tweet) like it says in the hint.
Then I tried to get the puts tweet["user"]["name"]... statement right but kept getting an error message "You did not generate the correct output."

Only after I delete the puts JSON.pretty_generate(tweet) line did the exercise compile without error. Something is being to strict here.

Also, the comment in line 16 says "...PRINT THE TWEET IN "screen name - text" FORMAT"
So I thought I could puts tweet["screen_name"] like in the previous exercise.
But no, it only works with puts tweet["user"]["name"] which I found quite confusing.

If that doesn't work, try puts "Raffi Krikorian - " + tweet["text"]. For me the problem was that my result didn't match the returned result when the course was designed. I think at that time, the user had his name as "Raffi Krikorian", but has since changed his name in Twitter to some upside down characters.
APIs by design return current information, and the problem here is probably that the course, while well-intentioned, can't be expected to keep up with every user change or API update that is made. In this situation, that means the actually correct output doesn't match the programmaticly expected "correct" output.

1 Comment

Oh, and just to chime in with the rest of you having similar comments:
tweet['user']['name'] passes while tweet['user']['screen_name'] does not, despite the instructions in the commented code on the line directly above saying ... easy fix that would save students a ton of frustration if anybody from Codecademy reads this forum.

First and foremost...

These API lessons are teaching
concepts that are constantly
evolving. Each of these API courses
involve a 3rd party API that can
change on a moments notice (can you
say FB?)

The requirements are outlined in the
source code mixed with instructions, but digging through it
is a pain. I consider myself an intermediate/experienced developer, and I knew what to do, and I still got a tad lost.

The course instructions are
definitely more geared towards
intermediate programmers who know
what they're looking for.

I want to help people pass this lesson, because this was written (as well as the other API docs) as a template that isn't relevant or expanding enough information to utilize them externally.

Sadly I am lost on this as well. I have tried many things. I am new to RubyGems but this is kind of nuts. And the hint does not help, at least for a Ruby novice like myself. I keep getting the error:

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.

Most of the API tutorials are only useful as a broad (and often error filled) overview in my experience. Even though that is anecdotal, the forums are filled with people having problems on all of them.

As a note, you should not be doing these if you have not at the very least gone through the associated language tutorial recently; or, are not an active developer in the language being used.

I saw this mentioned in a comment by apex on another answer, but putting it as a separate answer so that it's easier to find for others.

This issue is occurring because the API is returning the current (as at the time of this answer) value for tweet['user']['name'] which is different to the value when the course was written, so when you're putting the values that the API returns, it checks against a hard coded value which is now out of date, and it's consequently marking the answer incorrect.

The hint is correct, and the following code should be accepted: def print_tweet(tweet)
print "#{tweet['user']['name']} - #{tweet['text']}"
end

The workaround (at time of this answer) is to replace #{tweet['user']['name']} with the string which is expected by the course, so you'll end up with: print "Raffi Krikorian - #{tweet['text']}"

If that doesn't work, the tweet content may also have changed, so just print "Raffi Krikorian - want to work on large scale? \"Of course, we still have plenty more to do.\" #JoinTheFlock http://t.co/cEoSgiipnil" as that's what the course is checking for.

1 Comment

Thanks. It helped allot. There`s little mistake in your post. It should be >Blockquote print "Raffi Krikorian - want to work on large scale? course, we still have plenty more to do." #JoinTheFlock http://t.co/cEoSgiipnil" Blockquote<