The following code returns a huge JSON, but I only want to select 4 parameters of all those that are returned to me, what I am doing so far is console.log(tweets);
calling the parameter that I want to select, for example name
, with tweets.name
, but it always tells me that name
it does not it is defined. This would be the code I am using.
The parameters that I want to extract from this JSON are nested in a first instance in user
, and inside user
I have the parameters id
, name
, location
... which are the ones I intend to store.
twitterperfilesCtrl.getPerfiles = async(req, res) =>{
const twitterPerfiles = await twitterPerfil.find();
const contadorPerfiles = await twitterPerfil.countDocuments();
res.json(twitterPerfiles);
//console.log(twitterPerfiles[1].screen_name);
for(i = 0; i < contadorPerfiles; i++){
if (twitterPerfiles[i].id != true) {
var params = {screen_name: twitterPerfiles[i].screen_name};
client.get('statuses/user_timeline', params, function(error, tweets, response) {
if(!error){
console.log(tweets);
}
});
}
}
}
The Twitter documentation: https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html