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

Introduction to Twitter's API Forum

View Course

141 points
5528b52b51b88764b90003b7_172359692
Submitted by
N B
about 2 years ago

Access more tweet data! And Ruby arrays?

Ok, for a deeper dive to play around more with the Twitter API, you've learned that you can access:
tweet["user"]["screen_name"]

But why can't you access:
tweet['entities']['hashtags']['text']
?

I'm only interested in the text! Is there another format to go 3 levels? Or is that JSON data type handled differently?

Ultimately I'd like to turn the hashtag text from, say last 10 tweets, into a Ruby array. How would I do that?

Thanks for your advice and help!


1 vote

Best answer

permalink

Ok, seems to work this way:

tweet['entities']['hashtags'].each do |hashtag|
puts hashtag['text']
end

Or, into an array via:
array = Array.new
...
array.push hashtag['text']

141 points
5528b52b51b88764b90003b7_172359692
Submitted by
N B
about 2 years ago