0

I'm attempting to run ntwitter streaming API to track tweets about a certain hashtag, populating the Mongo collection Tweets with each tweet.

I've hooked it up server side like so:

t = new nTwitter({
    consumer_key: credentials.consumer_key,
    consumer_secret: credentials.consumer_secret,
    access_token_key: credentials.access_token_key,
    access_token_secret: credentials.access_token_secret
});

Meteor.methods({
  trackTweets: function () {
    this.unblock; // this doesn't seem to work
    console.log('... ... trackTweets');
    var _this = this;
    t.stream(
        'statuses/filter',
        { track: ['#love'] },
        function(stream) {
            stream.on('data', function(tweet) {
              // app/packages/mongo-livedata/collection.js:247
              //         throw e;
              //               ^
              // O yes I love her like money
              // Error: Meteor code must always run within a Fiber
                console.log(tweet.text);
                Tweets.insert(tweet.text); // this call blocks
            });
            stream.on('error', function(error, code) {
                console.log("My error: " + error + ": " + code);
            });
        }
    );
  }
});

The line: Tweets.insert(tweet.text) throws the must run inside its own Fiber error – and I've tried putting the this.unblock statement in several different places.

What should I do here?

4

2 に答える 2

1

関数 unblock を呼び出さないでください。

this.unblock;

これとともに:

this.unblock();

それがうまくいかない場合は、ntwitter がデータを取得する方法に関係があると思います。これを追加してみてください。

if (Meteor.isClient) return false;

メソッドがクライアントでは実行されず、サーバーでのみ実行されるようにする

于 2012-12-20T12:12:04.473 に答える
0

サーバー側で実行しているコードは、ファイバー内に含める必要があると思います。これらの回答には、同様の例がいくつかあります。

サーバーで Collection.insert を呼び出す場合、Meteor コードは常にファイバー内で実行する必要があります。

stdout を Meteor Web サイトにストリーミングする

于 2012-12-20T14:20:34.857 に答える