MeteorJs - http呼叫中的错误

时间:2015-04-29 13:44:08

标签: javascript meteor github-api

这是我的第一个Meteor程序,我试图对Github进行http调用。我面临的错误是这样的:

  

提供调用结果的例外情况' getUserInfo':["点击按钮"] /< @ 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   连接/ @的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://本地主机:3000 /包/ ddp.js d1840d3ba04c65ffade261f362e26699b7509706:156:9   SockJShttp://本地主机:3000 /包/ ddp.js d1840d3ba04c65ffade261f362e26699b7509706:1141:5   SockJShttp://本地主机:3000 /包/ ddp.js d1840d3ba04c65ffade261f362e26699b7509706:1199:13   SockJShttp://本地主机:3000 /包/ 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进行调用,我仍然会收到错误。

要解决这个问题究竟需要做些什么?

更新 这是服务器日志:

  

调用方法' getUserInfo' ReferenceError:未定义GitHub   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)?在maybeAuditArgumentChecks(packages / ddp / livedata_server.js:1617:1)   I20150429-19:22:53.064(5.5)?在packages / ddp / livedata_server.js:648:1   I20150429-19:22:53.064(5.5)?在[object Object] ._。extend.withValue(packages / meteor / dynamics_nodejs.js:56:1)   I20150429-19:22:53.064(5.5)?在packages / ddp / livedata_server.js:647:1   I20150429-19:22:53.064(5.5)?在[object Object] ._。extend.withValue(packages / meteor / dynamics_nodejs.js:56:1)   I20150429-19:22:53.064(5.5)?在[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

1 个答案:

答案 0 :(得分:1)

好的,我建议您安装this lovely package

meteor add bruz:github-api

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

聊天后编辑:到目前为止,此软件包的自述文件已过时。要使用此示例中显示的此程序包,您需要调用此代码而不是require("github")

Npm.require('github-api');

然后示例的其余部分应该没问题。应尽快提出拉动请求以要求更新。