Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Google Images API
    primarykey
    data
    text
    <p>I'm trying to use Google's Images API to search an image and put it into my html document as a div. This is what I have so far, but nothing seems to be appearing. This is parts from <a href="http://code.google.com/apis/imagesearch/v1/devguide.html" rel="nofollow">http://code.google.com/apis/imagesearch/v1/devguide.html</a>. This is my first time using an API, so I'm not sure what is really going on.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Art Project FTW&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;br&gt; &lt;br&gt; &lt;form name="upload" method="post" action="parse_image.php" enctype="multipart/form-data"&gt; &lt;input type="file" name="Image"&gt;&lt;br&gt; &lt;input type="submit" value="Upload Image"&gt; &lt;/form&gt; &lt;script type="text/javascript" src="https://www.google.com/jsapi?key=xxx"&gt;&lt;/script&gt; &lt;script type="text/javascript" charset="utf-8"&gt; google.load('search', '1'); function searchComplete(searcher) { // Check that we got results if (searcher.results &amp;&amp; searcher.results.length &gt; 0) { // Grab our content div, clear it. var contentDiv = document.getElementById('content'); contentDiv.innerHTML = ''; // Loop through our results, printing them to the page. var results = searcher.results; for (var i = 0; i &lt; results.length; i++) { // For each result write it's title and image to the screen var result = results[i]; var imgContainer = document.createElement('div'); var title = document.createElement('h2'); // We use titleNoFormatting so that no HTML tags are left in the title title.innerHTML = result.titleNoFormatting; var newImg = document.createElement('img'); // There is also a result.url property which has the escaped version newImg.src = result.tbUrl; imgContainer.appendChild(title); imgContainer.appendChild(newImg); // Put our title + image in the content contentDiv.appendChild(imgContainer); } } } function onload() { // Our ImageSearch instance. var imageSearch = new google.search.ImageSearch(); // Restrict to extra large images only imageSearch.setRestriction(google.search.ImageSearch.RESTRICT_IMAGESIZE, google.search.ImageSearch.IMAGESIZE_MEDIUM); // Here we set a callback so that anytime a search is executed, it will call // the searchComplete function and pass it our ImageSearch searcher. // When a search completes, our ImageSearch object is automatically // populated with the results. imageSearch.setSearchCompleteCallback(this, searchComplete, [imageSearch]); // Find me a beautiful car. imageSearch.execute("Subaru STI"); } google.setonloadCallback(onload);​ &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload