客户端不返回对Instagram API的Meteor异步调用。服务器端返回
服务器端:客户端不返回对Instagram API的Meteor异步调用。服务器端返回,meteor,Meteor,服务器端: Meteor.methods({ getFromInstagram: function(){ console.log("called!"); Future = Npm.require('fibers/future'); var myFuture = new Future(); var url = "https://api.instagram.com/v1/media/popular?access_toke
Meteor.methods({
getFromInstagram: function(){
console.log("called!");
Future = Npm.require('fibers/future');
var myFuture = new Future();
var url = "https://api.instagram.com/v1/media/popular?access_token=[ACCESSTOKEN]";
Meteor.http.get(url, function(error, results){
if(error){
myFuture.throw(error);
} else {
myFuture.return(results);
}
});
console.log( myFuture.wait() );
return myFuture.wait();
}
});
客户端:
instagramContent = Meteor.call("getFromInstagram");
console.log(instagramContent);
服务器端控制台日志工作并返回一个对象
Chrome控制台中的客户端控制台日志返回未定义。我忽略了什么?客户端将始终是异步的 尝试以下方法:
instagramContent = Meteor.call("getFromInstagram", function (error, result) {
console.log(result);
});
从文档()中:
在客户机上,如果不传递回调且不在存根中,则调用将返回undefined,并且无法获取方法的返回值。这是因为客户端没有光纤,所以实际上没有任何方法可以阻止方法的远程执行
太棒了,谢谢!成功了。顺便问一下,我的Meteor.Meteor方法的服务器代码是否正确?我是否仍然需要指定在客户端上使用
futures/fibers
?Doh:,如果不传递回调且不在存根中,则调用将返回未定义的,并且无法获取方法的返回值。这是因为客户机没有光纤,因此实际上没有任何方法可以阻止方法的远程执行。
除了未来,我不知道其他方法。我见过其他的实现,但刚才找不到示例,抱歉。