【问题标题】:Async API call error异步 API 调用错误
【发布时间】:2015-11-30 01:35:09
【问题描述】:

我目前正在尝试使用流星调用 twitter API,到目前为止我得到了这个:

updateTotalFoll:function(){
var Twit = Meteor.npmRequire('twit');

var T = new Twit({
  consumer_key:  'AWzYAlWFRh9zsownZMg3',
  consumer_secret: 'aYpL3zMPfqRgtX1usPQpEREEXVNPfNYna9FiIwTeDYR',
  access_token:  '4175010201-TEp9qNKO4mvjkj0GMjJFZIbGPYaVv4',
  access_token_secret:  'EPpcJyN27E4PvhJpYaTHflNFOv3DuR05kTP2j'
});

var Id2=RandomCenas.findOne({api:"twitter"})._id;

T.get('statuses/user_timeline', { screen_name: 'jeknowledge' },  function (err, data, response){
  //console.log(data[0].user.followers_count);
  RandomCenas.update(Id2,{$set:{totalFoll:data[0].user.followers_count}});
});

}

其中“RandomCenas”是一个 MongoDB。 我正在尝试使用来自通话的信息​​更新此集合,但我收到此错误

 Error: Meteor code must always run within a Fiber. 
 Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.

我已经在网上搜索了一种方法来解决这个问题,但我似乎无法应用我遇到的解决方案。 对我如何处理这个问题有任何帮助吗?

【问题讨论】:

  • 哦,我正在使用 twit 包

标签: twitter meteor


【解决方案1】:

这样试试

T.get('statuses/user_timeline', { screen_name: 'jeknowledge' },  Meteor.bindEnvironment(function (err, data, response) {
  //console.log(data[0].user.followers_count);
  RandomCenas.update(Id2,{$set:{totalFoll:data[0].user.followers_count}});
}));

发生这种情况的原因是因为您传递的回调函数发生在当前 Meteor 的 Fiber 之外检查答案Error: Meteor code must always run within a Fiber

【讨论】:

  • 成功了,非常感谢您的帮助!我被困了几天,现在我可以继续了!干杯
猜你喜欢
  • 2016-03-30
  • 1970-01-01
  • 1970-01-01
  • 2018-01-30
  • 2022-01-19
  • 2017-10-28
  • 2020-07-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多