Thursday, 8 June 2017

Store data from twitter api javascript (nodejs)

I seem to be having an issue. I'm trying to export data from the twitter api but I can't. Here's what my code looks like :

/// Twitter.js
module.exports = Twitter

function Twitter(twitter) {
    this.twitter = twitter
}

Twitter.prototype.friends = function(params) {
    this.twitter.get('friends/list', params, (err, data) => {
        if (err)
            console.log(err)

        console.log(data) // this prints data to the console but 
                          // I want to export and save in a data structure
                          // array or object
    }
}

///bot.js
var Twit = require('twit')
var config = require('/path_to_config.js')
var init = Twit(config)
var Twitter = require('/path_to_Twitter.js')

var bot = new Twitter(config)
bot.friends({ screen_name: 'myscreenname'})

If I try returning the data parameter it returns undefined and if i push data.users to an array it returns an empty array. Any help is and will be appreciated.



via m8r1x

No comments:

Post a Comment