Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

So I've been using the twitter API w/MeteorJS and what I'm attempting to do is just display the screen name of the twitter user 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;
      }
    )
  }
});

So I call the method 'screenName' from my isClient side. I call it from my client side like this:

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

On the server side, its printing out the correct value on console but it is not able to return that value. It keeps displaying undefined.

I am a javascript beginner so I might be making a mistake that I'm not seeing right away so if someone could please help me, I would highly appreciate it.

Thanks!

like image 221
halapgos1 Avatar asked Jul 27 '15 18:07

halapgos1


1 Answers

You need to place a function inside the call to be able to get the return.

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

You can read more in the documentation about the call function: http://docs.meteor.com/#/full/meteor_call

like image 183
Sceptic Avatar answered Oct 03 '22 12:10

Sceptic