0

js and request module and

I don`t know why different pixabay api result between http request in browser and http request in nodejs.

My code is:

var request = require('request');
var query = 'https://pixabay.com/api/?key='+config.pixabayKey+'&q=커피'+'&safesearch=true&lang=ko&page='+data.pixa_image_page+'&image_type='+data.pixa_image_type;
request(query, function(error, response, body){
    if(!error&&response.statusCode==200){
        var result =JSON.parse(body);
        console.log(body);
        socket.emit('pixa_image_result' , result);
    } else{
        socket.emit('pixa_image_result' , {result:false});
    }
});

and this result has only 2, but result in http same query request using web browser result is 500.

It is really same query. I don`t know why is different

Please help me.

Blauharley
  • 4,186
  • 6
  • 28
  • 47
장형준
  • 31
  • 4
  • 2 or 500 what ? items ? + show your those responses ? – l2aelba Jan 05 '18 at 12:22
  • my query is https://pixabay.com/api/?key={pixabaykey}&q=커피&safesearch=true&lang=ko&page=1&image_type=all and in my code `{"totalHits":2,"hits":[{"previewHeight":49,"likes":17,"favorites":7,"tags":"\ud3b8\uc9c0, a, \uae08","webformatHeight":212,"views":1016,"webformatWidth":640,"previewWidth":150,"comments":6,"downloads":247,"pageURL":"https://pixab...675_250x250.png","imageHeight":1920}],"total":2} ` – 장형준 Jan 06 '18 at 06:13
  • yes Hits items... – 장형준 Jan 06 '18 at 06:16

1 Answers1

0

First off, the Pixabay API is limited to return up to 500 matches. The total number of available hits on the website is included only as a number in the API response.

In your case, make sure that the q param is properly URL encoded. The values of data.pixa_image_page and data.pixa_image_type in your request are unknown. If, for example, image_type is "vector", there will be fewer matches than for "photo".

Maybe that helps ...

Simon Steinberger
  • 6,605
  • 5
  • 55
  • 97