How to return value in Meteor.call () in the client?

So, I'm using the twitter API w / MeteorJS, and what I'm trying to do is just show the Twitter username on the browser. This is what I have done so far:

Meteor.methods({ 'screenName': function() { T.get('search/tweets', { q:'#UCLA', count:1 }, function(err,data,response) { console.log(data.statuses[0].user.screen_name); return data.statuses[0].user.screen_name; } ) } }); 

Therefore, I call the 'screenName' method on my part isClient. I call it from my client side as follows:

  var temp = Meteor.call('screenName'); 

On the server side, it displays the correct value on the console, but cannot return this value. It continues to display undefined.

I am a beginner of javascript, so I can be wrong that I donโ€™t see right away, so if someone can help me, I would really appreciate it.

Thanks!

+7
javascript meteor twitter
source share
1 answer

You need to put the function inside the call to get the return.

 Meteor.call( 'screenName', function(error, result){ if(error){ console.log(error); } else { console.log(result); } } ); 

More information on the call function can be found at http://docs.meteor.com/#/full/meteor_call

+10
source share

All Articles