On the client I have the following code that’s supposed to get tweets from the server:
Meteor.call('twitter.tweets', userArea(), function(error, tweets) {
console.log(tweets);
});
On the server I have tried this code:
'twitter.tweets'(userArea) {
let twit = require('twit')
let twitter = new twit({ });
var hash;
twitter.get('search/tweets', { q: '#' + userArea, result_type: 'popular', count: 15 }, function(error, tweets) {
hash = tweets;
console.log(hash) // displays tweets
});
console.log(hash) // doesn't display tweets
}
I need the tweets that are available in the callback, but they aren’t available out of the callback. I have also tried using a function with this
and assigning the tweets to this
, although that doesn’t work either.
'twitter.tweets'(userArea) {
let twit = require('twit')
let twitter = new twit({ ... });
function hash (error, tweets) {
if(error) console.log(error)
this.tweets = tweets;
console.log(this.tweets);
}
var hashes = new hash(null, 'none');
let twitter = new twit({ });
twitter.get('search/tweets', { q: '#' + userArea, result_type: 'popular', count: 15 }, hashes);
console.log(hashes.tweets); // displays object of tweets as 'none'
return hashes;
}
This doesn’t work either. What would be the best approach and what would fix it?