Methods not found


#1

Hi community,

I would like get my server methods on client, but i’ve ‘error 404’ when i try to show my screenName. My code :

`if (Meteor.isServer) {

Meteor.startup(function () {

    var Twit = require('twit');

    apiKeys = {
        consumer_key: 'xxx', // API key
        consumer_secret: 'xxx', // API secret
        access_token: 'xxx',
        access_token_secret: 'xxx'
    }

    var T = new Twit(apiKeys);

    T.get('statuses/user_timeline', { screen_name: 'ILeG3nDz', count: 2 }, Meteor.bindEnvironment(function(err, data, response) {

        Meteor.methods({

            screenName: function() {
                return data;
            }

        })

    }));

});

}

if (Meteor.isClient) {

Meteor.call('screenName', function (error, result) {

    if (error) {

        console.log(error);

    } else {

        //console.log(result[0].text);
        Session.set('test', result[0].text);

    }

});

Template.latestTweet.helpers({

    getTweet: function () {

        return Session.get('test');

    }

});

}`

I don’t know why i’ve this error. Do you have idea ?

Object { stack: "Meteor.makeErrorType/errorClass@htt…", error: 404, reason: "Method 'screenName' not found", details: undefined, message: "Method 'screenName' not found [404]", errorType: "Meteor.Error" }

Thank you !


#2

Try declaring your Meteor.methods() outside of the startup function.


#3

Hi !

Methods not found too


#4

I don’t know why, but now i’ve just :

Exception in delivering result of invoking 'screenName'

Exception in callback of async function

Exception in template helper: getTweet


#5

I’m thinking you’d want something like this, if you want to use bindEnvronment. Note, I haven’t tested this!

import { Meteor } from 'meteor/meteor';

const Future = require('fibers/future');
const Twit = require('twit');

const apiKeys = {
  consumer_key: 'xxx', // API key
  consumer_secret: 'xxx', // API secret
  access_token: 'xxx',
  access_token_secret: 'xxx',
}

const T = new Twit(apiKeys);

Meteor.methods({
  screenName: function() {
    T.get('statuses/user_timeline', { screen_name: 'ILeG3nDz', count: 2 }, Meteor.bindEnvironment((err, data, response) => {
      if (error) {
        Future.throw(error);
      } else {
        Future.return(data);
      }
    }));
    return Future.wait();
  },
});

But, if you don’t want to use the response parameter, wrapAsync is easier.