它非常简单的流星素描,我想在这里做一个远程API调用,以访问envato api流星js的http远程API访问:我在这里做错了什么?
但我所得到的是'未定义'。
我相信它很简单,但我只是无法弄清楚。任何帮助都是极好的。
下面是代码:
if (Meteor.isClient) {
// counter starts at 0
Session.setDefault("counter", 0);
Template.hello.helpers({
counter: function() {
return Session.get("counter");
}
});
Template.hello.events({
'click button': function() {
// increment the counter when button is clicked
Meteor.call("account", function(error, result) {
console.log(result);
});
Session.set("counter", Session.get("counter") + 1);
}
});
}
if (Meteor.isServer) {
Meteor.startup(function() {
// code to run on server at startup
});
Meteor.methods({
account: function() {
// Returns 'undfined'
//return HTTP.get("http://marketplace.envato.com/api/edge/USERNAME/APIKEY/account.json").data;
//works just fine.
return HTTP.get("http://marketplace.envato.com/api/edge/total-users.json").data;
}
});
}
有趣的是,它工作正常,当我使用它不需要USERNAME和APIKEY例如公共API集http://marketplace.envato.com/api/edge/total-users.json
我花了足够的时间和双重检查了一切。我在这里错过了什么?想法?
由于Akshat ...它仍然是相同的应将来用于尝试帮助它“未定义”? – 2014-11-01 04:03:22
@ user1348976我给你的代码对我来说完全和上面一样。如演示在这里:http://meteorpad.com/pad/7J2D6bAWA87QiMKbu。请同时检查您是否添加了http包 – Akshat 2014-11-01 06:27:41
正如您在共享的Meteorpad上的API调用一样: return HTTP.get(“http://marketplace.envato.com/api/edge/total-users.json”) 。数据; 工作般的魅力,因为开始 但下面的API调用返回“未定义” 回报HTTP.get(“http://marketplace.envato.com/api/edge/RisingThemes/no1keq2xhphjw9ntgwdq0urav6fdeqm2/account.json”)。数据; 什么可能是错的?我检查了HTTP封装和凭据是正确的,点击curl http://marketplace.envato.com/api/edge/RisingThemes/no1keq2xhphjw9ntgwdq0urav6fdeqm2/account.json 正常工作。 – 2014-11-01 07:24:15