MeteorJs - http 调用错误

MeteorJs - Error in an http call

这是我的第一个 Meteor 程序,我正在尝试对 Github 进行 http 调用。我遇到了这样的错误:

Exception in delivering result of invoking 'getUserInfo': ["click button"]/<@http://localhost:3000/helloMeteor.js?823f404b37c246a7d23ae50a10c37969e426b2b8:18:17 Meteor.bindEnvironment/<@http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:983:17 ._maybeInvokeCallback@http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:3860:7 .receiveResult@http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:3880:5 ._livedata_result@http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4964:7 Connection/onMessage@http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:3725:7 ._launchConnection/self.socket.onmessage/<@http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:2717:11 _.forEach@http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:156:7 ._launchConnection/self.socket.onmessage@http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:2716:9 SockJShttp://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:156:9 SockJShttp://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1141:5 SockJShttp://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1199:13 SockJShttp://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1346:9

这是我的代码:

if (Meteor.isClient) {
// counter starts at 0
Session.setDefault('counter', 0);

Template.hello.helpers({
    counter: function () {
        return Session.get('counter');
    }
});

//This is how you bind event handlers
//Format: eventtype selector
Template.hello.events({
    'click button': function () {
        // increment the counter when button is clicked
        Session.set('counter', Session.get('counter') + 1);
        Meteor.call('getUserInfo', 'rutwick', function(err, res) {
            console.log(result);
        });
    }
});
}

if (Meteor.isServer) {
//Meteor.startup(function () {
    // code to run on server at startup
    Meteor.methods({
        getUserInfo: function(userN) {
            var github = new GitHub({
                version: "3.0.0", // required
                timeout: 5000     // optional
            });

            var result = github.user.getFollowingFromUser({
                user: userN
            });

            return result;
        }
    });
//});
}

我正在使用 Github API JavaScript 包装器。即使我尝试使用简单的 HTTP 进行调用,我仍然会收到错误消息。

具体需要做什么来解决这个问题?

更新 这是服务器日志:

Exception while invoking method 'getUserInfo' ReferenceError: GitHub is not defined I20150429-19:22:53.064(5.5)? at [object Object].Meteor.methods.getUserInfo (app/helloMeteor.js:29:34) I20150429-19:22:53.064(5.5)? at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1617:1) I20150429-19:22:53.064(5.5)? at packages/ddp/livedata_server.js:648:1 I20150429-19:22:53.064(5.5)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1) I20150429-19:22:53.064(5.5)? at packages/ddp/livedata_server.js:647:1 I20150429-19:22:53.064(5.5)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1) I20150429-19:22:53.064(5.5)? at [object Object]._.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646:1) I20150429-19:22:53.064(5.5)? at packages/ddp/livedata_server.js:546:1

好的,我建议你安装this lovely package:

meteor add bruz:github-api

根据我链接到的网页上的示例,它应该允许您在服务器端使用 Github API。

聊天后编辑: 到目前为止,这个包的自述文件已经过时了。要像示例中所示使用此包,您需要调用它而不是 require("github"):

Npm.require('github-api');

那么示例的其余部分应该没问题。应该尽快提出拉取请求以请求更新。