Skip to content Skip to sidebar Skip to footer

Why Is Undefined Being Returned For Meteor.call() In Client?

So I'm attempting to access the twitter REST API and retrieve the screen name of a tweet. I feel like my code will be better explanation: I'm calling the method 'screenName' from t

Solution 1:

Your server method needs to be synchronous. The callback in the method is returning after the method has already returned undefined. I'd like to be more specific but I'm not sure what library you are using.

You can get a feel for this by looking at the examples from the HTTP.call documentation. Your code could look something like this:

Tget = Meteor.wrapAsync(T.get);

Meteor.methods({
  'screenName': function() {
    try {
      var result = Tget('search/tweets', {q:'#UCLA', count:1});
      return result.statuses[0].user.screen_name;
    } catch (e) {
      returnfalse;
    }
  }
});

See the docs for more information on wrapAsync.

Solution 2:

You are only returning data.statuses[0].user.screen_name from your inner function. You need to return it from your screenName method to have it available in Meteor.call().

Post a Comment for "Why Is Undefined Being Returned For Meteor.call() In Client?"