使用Node.js从twitter搜索api中提取有用的数据

时间:2017-09-16 06:37:46

标签: node.js twitter

我需要从twitter search api获取像created_at,retweet_count这样的信息, 这是我从twitter上搜索的代码

app.get('/tweets', function (req, res) {
    client.get('search/tweets', params, function (err, data, response) {
        if (!err) {
            console.log(data)
            //var lines = data.split(" ")
            for (var i = 0; i < data.length; i++) {
                console.log(data[i].created_at)
                console.log(data[i].id)
                console.log(data[i].text)
                console.log(data[i].user)
                console.log(data[i].retweet_count)
            }
        } else {
            console.log(err);
        }
    })
})

这工作正常,我在我的控制台中得到了这个

 { statuses:
   [ { created_at: 'Sat Sep 16 06:24:04 +0000 2017',
       id: 908939524637470700,
       id_str: '908939524637470720',
       text: 'Re: Which market holds more coins? Japan or Korean. #Bitcoin_Discussion #bitcoin #blockchain',
       truncated: false,
       entities: [Object],
       metadata: [Object],
       source: '<a href="https://dlvrit.com/" rel="nofollow">dlvr.it</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: 0,
       favorite_count: 0,
       favorited: false,
       retweeted: false,
       possibly_sensitive: false,
       lang: 'en' }, .... so on

我需要从这些数据中提取created_at,id,retweet_count,任何人都可以帮助我......

1 个答案:

答案 0 :(得分:1)

正如Prakash所指出的,你只需要遍历updates = (v for v in indefinite_dict.values() if v not in immediate_instantiation) immediate_instantiation.update(zip(updates, variables))

data.statuses