title: Getting the first image of a Google Image search using their Custom Search Engine in Javascript
body: <p>I'm attempting to extract the URL of the first image to appear from a search based on the bar code number or UPC of a product. It's just a long number.</p>
  
  <p>I have something which works using Google, but it's with their deprecated search service. Here's a piece of the code which I'm using:</p>
  
  <pre><code>    google.load('search', '1');
      ...
      function OnLoad() 
      {
          // Create an Image Search instance.
          imageSearch = new google.search.ImageSearch();
  
          // Set searchComplete as the callback function when a search is 
          // complete.  The imageSearch object will have results in it.
          imageSearch.setSearchCompleteCallback(this, searchComplete, null);
  
  
          imageSearch.execute(&lt;?=json_encode($upc['upc']);?&gt;);
  
          // Include the required Google branding
          google.search.Search.getBranding('branding');
      } 
  </code></pre>
  
  <p>From what I understand, that google.search.ImageSearch() is deprecated, which may mean they will limit the number of queries allowed. What they want me to use is their new Custom Search Engine API. Looking at their documentation, it looks like it's all about setting up a custom search bar, which isn't what I actually want. I'm looking to do a quick search for the first image to pop up from a given search of the UPC and use that as a placeholder image until a preferred image is loaded.</p>
  
  <p>I'm just looking for the best way to get an image from a simple Google Search, that's what I'm really after. </p>
  
  <p>Cheers! </p>