I am using the twit
npm package and having trouble with using it asynchronously in a method.
I get the error :
“Exception while invoking method ‘getTweets’ TypeError: this.request is not a function”
Meteor.methods({
'getTweets': function () {
var T = new Twit({
consumer_key: 'my_key_works',
consumer_secret: 'my_secret_works',
access_token: 'my_token_works',
access_token_secret: 'my_secret_token_works'
});
var node = 'statuses/user_timeline';
var query = {
q: 'screen_name%3Atwitter',
count: 5,
exclude_replies: true,
};
var callback = function(err, data) {
if(err){
console.log(err);
}
else{
var objs = [];
for (i=0;i<data.length;i++){
var obj = {
created_at: data[i].created_at,
text: data[i].text,
user_name: data[i].user.name,
user_screen_name: data[i].user.screen_name,
user_url: data[i].user.url
};
objs.push(obj);
}
objs = JSON.stringify(objs);
return(objs);
}
});
var c = Meteor.wrapAsync(T.get);
var res = c(node,query,callback);
return res;
}
});
Template.Tweets.onRendered(function () {
Meteor.call('getTweets', {}, function(error, result){
if(error){
console.log(error);
}else{
console.log(result);
}
});
});