api google images

Asked

Viewed 229 times

0

Community, I’m having problems using the google search api (images), where it does not return me the possible results, for example, I do a search related to the car and it returns me images that are not of cars and does not return the minimum amount that is set as default which is 10.

am using this example from google itself: https://developers.google.com/custom-search/v1/using_rest

where mine is as follows:

 <!DOCTYPE html> <html>

<html>
  <head>
    <title>JSON Custom Search API Example</title>
  </head>
  <body>
    <div id="content"></div>
    <script>
      function hndlr(response) {
      for (var i = 0; i < response.items.length; i++) {
        var item = response.items[i];
        // in production code, item.htmlTitle should have the HTML entities escaped.
        document.getElementById("content").innerHTML += "<br>" + item.htmlTitle;
      }
    }
    </script>
    <script src="https://www.googleapis.com/customsearch/v1?searchType=image&key=MINHA_KEY&cx=MINHA_ID_MACHINE&q=carros&callback=hndlr">
    </script>
  </body>
</html>

My machine id is already enabled the option of images, even so in this case it returns nothing, from the following error:

Uncaught TypeError: Cannot read property 'length' of undefined
    at hndlr (testePesquisa.html:50)
    at v1?

Some light please?

EDIT:

Ahhh, I kind of found the problem, where you have the option "search sites" I was putting: www.google.com I deleted and added *.com and *.com.br and Assi I was able to satisfy my search, but the problem is, I really have to put those terms (.com and .br....) or do you have a General term? because I tested leaving empty and returned nothing.

  • Put a console.log(response) at the beginning of the function and see what returns. This error quoted is because there is no object response.items, so there’s no way of knowing length because it is "undefined" (undefined).

  • returned nothing.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.