0

I am using Diffbot analyze API for detecting the page type and I want result like this

{"stats":{"times": {"docParseTime":0,"docGlobalsTime":0,"fetchAndRenderTime":586,"typeTime":0},"fromCache":true,"types":{"recipe":0,"discussion":0,"audio":0,"error":0,"location":0,"faq":0,"image":0,"job":0,"download":0,"game":0,"product":0,"frontpage":0,"document":1,"article":0,"event":0,"chart":0,"serp":0,"reviewslist":0,"video":0,"profile":0}},"request":{"pageUrl":"http://www.irs.gov/pub/irs-pdf/fw4.pdf","api":"analyze","version":3,"options":["stats"]},"type":"other","objects":[]}

but currently I am getting like this

{"request":{"pageUrl":"http://static.nfl.com/static/content/public/image/rulebook/pdfs/2013%20-%20Rule%20Book.pdf","api":"analyze","version":3},"type":"other","objects":[]}

I have to pass 'stats' argument in request. But where in request, I can pass this argument. Thanks,

abdulbarik
  • 6,101
  • 5
  • 38
  • 59

1 Answers1

0

Hi I got it and here is the solution, just customize the Diffbot lib file or write in your file its up to you, and here is the code

var diffbot = new Diffbot('xxxxxxxxxxxxxxxxx');
diffbot.analyze({
uri: "http://www.visitcalifornia.in/media/pages/getting_around/maps/ORANGE-COUNTY.pdf",
html: true,
comments: true,
stats: true
}, function(err, response) {
}

And here is the customize library code

Diffbot.prototype.analyze = function (options, callback) {
  for (var i in options) {
   this[i] = options[i];
  }

  var options = this;
  // support 'url'
  if (options.url) {
    options.uri = options.url;
    delete options.url;
  }

  if (!options.uri) {
    throw new Error("the URI is required.");
  }

  var diffbot_url = "http://api.diffbot.com/v3/analyze?token=" + this.token + "&url=" +  encodeURIComponent(options.uri)+"&fields=stats"; 
  if (options.stats) {
     diffbot_url += "&stats=1";
  }

  request({uri: diffbot_url}, function(error, response, body) {
     if (error) {
       callback(error, undefined);
     } else {
      callback(false, JSON.parse(body));
     }
  });
}

it works as charm!

abdulbarik
  • 6,101
  • 5
  • 38
  • 59