[RESOLVED] Adding twitter followers ids in a Mongo collection using node npm 'twit' module


#1

Meteor.methods({

// this is the server method called from the client

getTwitterFollowersIDsCollectionsClient : function (screenname){
  Meteor.setTimeout(function(screenname){
    T.get('followers/ids', { screen_name: screenname }, function (err, data, response) {
    console.log("from getTwitterFollowersIDsCollectionsClient : "+data.ids);
    var vids = data.ids;
    for(var i in vids)
      {
        TwitterFollowersIDsCollecions.insert({
          twitterFollowerID:vids[i]
        });
      }
    return data;
  });

  },10);
  return;
}

});

I am getting Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
The objective is to store all twitter follower ids in a Mongo collection and then to render on the browser through template and helper using the stored Mongo collection.

Originally asked in SO @ http://stackoverflow.com/questions/30019539/meteor-wrapasync-save-twitter-rest-response-to-mongo-collection-giving-an-error/30021324?noredirect=1#comment48178710_30021324


#3

Resolved. I was finally able to store the twitter follower ids to a Mongo collection by adding Meteor.bindEnvironment to T.get callback method

getTwitterFollowersIDsCollectionsClient : function (screenname){
  Meteor.setTimeout(function(screenname){
    T.get('followers/ids', { screen_name: screenname }, Meteor.bindEnvironment(function (err, data, response) {
    console.log("from getTwitterFollowersIDsCollectionsClient : "+data.ids);

    var vids = data.ids;
    for(var i in vids)
      {
        TwitterFollowersIDsCollecions.insert({
          twitterFollowerID:vids[i]
        });
      }
      
    return data;
  }));

  },10);
  return;
}