Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return full JSON of Tweet from Twitter Gem Twitter Object

So I have some code:

#twitter api access config up here
Twitter.status(27558893223)

and I know I get all the tweet information from that Twitter.status line. What I want though isn't a Ruby object. I want the full JSON of that tweet so I can directly use it in populating my mongodb instance. Can I get some help on how to convert that tweet object into just JSON?

Thanks!

like image 957
Ben Nelson Avatar asked Jan 13 '23 18:01

Ben Nelson


2 Answers

Couldn't you use JSON.generate method on Tweet.attrs?

like image 181
Marcin Pietraszek Avatar answered Jan 16 '23 07:01

Marcin Pietraszek


It mostly depends what all columns you want to populate in your DB. The doc here mentions pretty good info on what all elements you can fetch from Twitter::Tweet.

For instance you can do things like mentioned below and store it accordingly to your DB instance.

Twitter.status(27558893223).source
Twitter.status(27558893223).from_user
Twitter.status(27558893223).from_user_id 
Twitter.status(27558893223).lang

Or you could do Twitter.status(27558893223).attrs and handle the JSON accordingly.

Let me know if I understood the question wrong.

like image 42
shayonj Avatar answered Jan 16 '23 08:01

shayonj