notslang/instagram-screen-scrape

Newbie could not get comments

ergunkocak opened this issue · 1 comments

Hi,

First of all my first time on node :) And totally liked the job you did. My problem is I can get posts but not comments. Here is my code : (please do not judge the spagetti :) )

var util = require ('util'),
url = require('url'),
http = require('http'),
qs = require('querystring');

var InstagramPosts, streamOfPosts;
InstagramPosts = require('instagram-screen-scrape');

var InstagramComments, streamOfComments;
InstagramComments = require('instagram-screen-scrape');

http.createServer(function (request, response) {

  // Send the HTTP header 
  // HTTP Status: 200 : OK
  // Content Type: text/plain

  response.writeHead(200, {'Content-Type': 'text/plain'});

  // Send the response body as "Hello World"


  var url_parts = url.parse(request.url,true);
  var user = url_parts.pathname.replace('/', '');

  sendEm(user, response)

}).listen(8081);

var itemToWait = 0;
var res;

function sendEm(user, response) {

  streamOfPosts = new InstagramPosts({
    username: user
  });

  streamOfPosts.on('data', function(post) {

    // each 2 second
    setInterval(function(){

      if(itemToWait == 0) {
        response.end('\n Done');
      }


    }, 2 * 1000);

    // var post;

    // post = streamOfPosts.read();

    itemToWait++;
    if(post != null) {
      if(post.comment > 0) {

        response.write(util.inspect(post) + '\n');

        streamOfComments = new InstagramComments({
          post: post.id
        });

        streamOfComments.on('data', function(comment) {
          // var comment;

          // comment = streamOfComments.read();

          itemToWait++;
          if(comment != null) {
            response.write('\n _1_ \n');
            response.write(util.inspect(comment));
            response.write('\n _2_ \n');

            itemToWait--;
          } else {

            itemToWait--;
            return;
          }

        });

      }
      response.write('\n\n');

      itemToWait--;
    } else {
      itemToWait--;
    }


  });

}

Sample url call : http://127.0.0.1:8081/username

Regards

I recently updated the comment scraping code (and released v2), which might fix your problem.

If it doesn't, then try cutting down your code until you find the root of the problem... For example, removing the HTTP server & trying a single call to get a stream of comments for a known user would be a good start... That way you can be certain that the bug isn't being introduced by anything else.