//Supongamos que 'tweets' es la respuesta de la API y contiene lo siguiente:
const tweets = [
{ created_at: 'Mon Apr 08 08:01:00 +0000 2019',
id: 1115162612998787100,
id_str: '1115162612998787072',
text:
'Editorial | El sistema de pensiones no está en quiebra; hay que confiar en la negociación social y política para ga… https://t.co/larIH30qja',
truncated: true,
entities:
{ hashtags: [], symbols: [], user_mentions: [], urls: [Array] },
source:
'<a href="https://about.twitter.com/products/tweetdeck" rel="nofollow">TweetDeck</a>',
in_reply_to_status_id: null,
in_reply_to_status_id_str: null,
in_reply_to_user_id: null,
in_reply_to_user_id_str: null,
in_reply_to_screen_name: null,
user:
{ id: 7996082,
id_str: '7996082',
name: 'EL PAÍS',
screen_name: 'el_pais',
location: 'Madrid',
description:
'Las noticias más relevantes y la última hora, por los periodistas de EL PAÍS. Para informarse y conversar. Únete al sistema de alertas mediante mensaje directo',
url: 'https://t.co/0o6oj1LRF2',
entities: [Object],
protected: false,
followers_count: 6878154,
friends_count: 755,
listed_count: 56357,
created_at: 'Mon Aug 06 16:20:09 +0000 2007',
favourites_count: 1657,
utc_offset: null,
time_zone: null,
geo_enabled: true,
verified: true,
statuses_count: 473495,
lang: 'es',
contributors_enabled: false,
is_translator: false,
is_translation_enabled: true,
profile_background_color: 'FFFFFF',
profile_background_image_url: 'http://abs.twimg.com/images/themes/theme1/bg.png',
profile_background_image_url_https: 'https://abs.twimg.com/images/themes/theme1/bg.png',
profile_background_tile: false,
profile_image_url:
'http://pbs.twimg.com/profile_images/815456059322036224/o_RQNEOh_normal.jpg',
profile_image_url_https:
'https://pbs.twimg.com/profile_images/815456059322036224/o_RQNEOh_normal.jpg',
profile_banner_url: 'https://pbs.twimg.com/profile_banners/7996082/1450772084',
profile_link_color: '0084B4',
profile_sidebar_border_color: 'FFFFFF',
profile_sidebar_fill_color: 'F1F4F9',
profile_text_color: '333333',
profile_use_background_image: false,
has_extended_profile: true,
default_profile: false,
default_profile_image: false,
following: true,
follow_request_sent: false,
notifications: false,
translator_type: 'none' },
geo: null,
coordinates: null,
place: null,
contributors: null,
is_quote_status: false,
retweet_count: 1,
favorite_count: 7,
favorited: false,
retweeted: false,
possibly_sensitive: false,
lang: 'es' },
{ created_at: 'Mon Apr 08 07:55:29 +0000 2019',
id: 1115161225120366600,
id_str: '1115161225120366593',
text:
'RT @demamasdepapas: Opinión | Niños que pegan: por qué agreden y cómo enseñarles a no hacerlo; por Ruth Alfonso Arias\nhttps://t.co/XiJoSqUi…',
truncated: false,
entities:
{ hashtags: [], symbols: [], user_mentions: [Array], urls: [] },
source:
'<a href="https://about.twitter.com/products/tweetdeck" rel="nofollow">TweetDeck</a>',
in_reply_to_status_id: null,
in_reply_to_status_id_str: null,
in_reply_to_user_id: null,
in_reply_to_user_id_str: null,
in_reply_to_screen_name: null,
user:
{ id: 7996082,
id_str: '7996082',
name: 'EL PAÍS',
screen_name: 'el_pais',
location: 'Madrid',
description:
'Las noticias más relevantes y la última hora, por los periodistas de EL PAÍS. Para informarse y conversar. Únete al sistema de alertas mediante mensaje directo',
url: 'https://t.co/0o6oj1LRF2',
entities: [Object],
protected: false,
followers_count: 6878154,
friends_count: 755,
listed_count: 56357,
created_at: 'Mon Aug 06 16:20:09 +0000 2007',
favourites_count: 1657,
utc_offset: null,
time_zone: null,
geo_enabled: true,
verified: true,
statuses_count: 473495,
lang: 'es',
contributors_enabled: false,
is_translator: false,
is_translation_enabled: true,
profile_background_color: 'FFFFFF',
profile_background_image_url: 'http://abs.twimg.com/images/themes/theme1/bg.png',
profile_background_image_url_https: 'https://abs.twimg.com/images/themes/theme1/bg.png',
profile_background_tile: false,
profile_image_url:
'http://pbs.twimg.com/profile_images/815456059322036224/o_RQNEOh_normal.jpg',
profile_image_url_https:
'https://pbs.twimg.com/profile_images/815456059322036224/o_RQNEOh_normal.jpg',
profile_banner_url: 'https://pbs.twimg.com/profile_banners/7996082/1450772084',
profile_link_color: '0084B4',
profile_sidebar_border_color: 'FFFFFF',
profile_sidebar_fill_color: 'F1F4F9',
profile_text_color: '333333',
profile_use_background_image: false,
has_extended_profile: true,
default_profile: false,
default_profile_image: false,
following: true,
follow_request_sent: false,
notifications: false,
translator_type: 'none' },
geo: null,
coordinates: null,
place: null,
contributors: null,
retweeted_status:
{ created_at: 'Mon Apr 08 07:55:16 +0000 2019',
id: 1115161170388844500,
id_str: '1115161170388844544',
text:
'Opinión | Niños que pegan: por qué agreden y cómo enseñarles a no hacerlo; por Ruth Alfonso Arias\nhttps://t.co/XiJoSqUiJL',
truncated: false,
entities: [Object],
source:
'<a href="https://about.twitter.com/products/tweetdeck" rel="nofollow">TweetDeck</a>',
in_reply_to_status_id: null,
in_reply_to_status_id_str: null,
in_reply_to_user_id: null,
in_reply_to_user_id_str: null,
in_reply_to_screen_name: null,
user: [Object],
geo: null,
coordinates: null,
place: null,
contributors: null,
is_quote_status: false,
retweet_count: 6,
favorite_count: 12,
favorited: false,
retweeted: false,
possibly_sensitive: false,
lang: 'es' },
is_quote_status: false,
retweet_count: 6,
favorite_count: 0,
favorited: false,
retweeted: false,
lang: 'es' }
];
// Recorremos los elementos del array:
tweets.forEach((tweet) => {
console.log('User id: ', tweet.user.id);
console.log('User name: ', tweet.user.name);
console.log('User location: ', tweet.user.location);
});
console.log(tweets)
?