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

Introduction to Twitter's API Forum

View Course » View Exercise

854 points
5135e55d066b60adc0003934_368363101
Submitted by
Morten Haugen
about 4 years ago

Error message given

Hi,
Codecademy's telling me I'm doing it right, but I still get some error messages. Can someone please help me? My code is given undeneath:

 baseurl = "https://api.twitter.com"
path    = "/1.1/statuses/show.json"
query   = URI.encode_www_form("id" => "266270116780576768")
address = URI("#{baseurl}#{path}?#{query}")
request = Net::HTTP::Get.new address.request_uri

# Print data about a Tweet
def print_tweet(tweet)
  # ADD CODE TO PRINT THE TWEET IN "<screen name> - <text>" FORMAT
  puts tweet["user"]["name"] "-" tweet["text"]
end

The error message:

:16: syntax error, unexpected tSTRING_BEG, expecting keyword_end
  puts tweet["user"]["name"] '-' tweet["text"]
                              ^
(ruby):16: syntax error, unexpected tIDENTIFIER, expecting keyword_end
  puts tweet["user"]["name"] '-' tweet["text"]
                                      ^

1 vote

permalink

In your first example, you need to add two hyphens and two spaces around the dash and append the strings. Please compare these two lines closely. This is what you wrote:
puts tweet["user"]["name"] '-' tweet["text"]

This is what it should look like:
puts tweet["user"]["name"] + ' - ' + tweet["text"]

612 points
30a3b2c53aa41697bbb6c08675472cf4?s=140&d=retro
Submitted by
OlafBom
about 4 years ago


1 vote

permalink

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.

Second:

Change this line...

query   = URI.encode_www_form("id" => "TWEET ID GOES HERE")

to show this:

query   = URI.encode_www_form("id" => "266270116780576768")

Change your print_tweet function:

# ADD CODE TO PRINT THE TWEET IN "<screen name> - <text>" FORMAT

to show this:

puts tweet["user"]["name"] + " - " + tweet["text"]

I would recommend reading up here: if you want to expand your knowledge.
http://programmers.stackexchange.com/questions/90531/how-to-learn-an-api

2126 points
512d3f8f7df8cbb462001736_165830919
Submitted by
Nicholas Hazel
over 3 years ago


0 votes

permalink

I changed my code a bit and thus avoided the issue:

# Print data about a Tweet
def print_tweet(tweet)
  # ADD CODE TO PRINT THE TWEET IN "<screen name> - <text>" FORMAT
  puts "#{tweet["user"]["name"]} - #{tweet["text"]}"
end

However, I still don't know why it didn't work. If you see the error, please advise me ;)

854 points
5135e55d066b60adc0003934_368363101
Submitted by
Morten Haugen
about 4 years ago