2013-05-07 25 views
0

我一直在尝试使用谷歌自定义搜索API,所以我可以从它下载图片,并允许用户使用它作为他们的“封面”照片。这甚至有可能吗?我可以得到图像搜索的结果,但他们似乎只拇指指甲大小:不能得到图像的原始网址

google.load("search", "1", { "nocss": true }); 
     google.setOnLoadCallback(OnLoad); 
     function OnLoad() { 

      // create a tabbed mode search control 
      var tabbed = new google.search.SearchControl(); 

      //restrict results: search only moderated 
      //tabbed.setRestriction(google.search.RESTRICT_SAFESEARCH, google.search.SAFESEARCH_STRICT); 

      // Set the Search Control to get the most number of results 
      tabbed.setResultSetSize(google.search.Search.LARGE_RESULTSET); 

      // create image searchers. 
      tabbed.addSearcher(new google.search.ImageSearch()); 


      // proprofscc: On search completeion 
      tabbed.setSearchCompleteCallback(this, bind_event); 

      // draw in tabbed layout mode 
      var drawOptions = new google.search.DrawOptions(); 
      drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED); 

      // Draw the tabbed view in the content div 
      tabbed.draw(document.getElementById("googleImageSearch"), drawOptions); 

      // Search! 
      tabbed.execute(""); 
     } 
     function bind_event() { 



      $("a.gs-image").bind("click", function (e) { 
       $("#hidden-upload-image").attr("src", $(this).children("img").attr('src')); 

       //alert($(this).children("img").attr('src')); 

       $("#imageContainer").html('<img src="' + $(this).attr('href') + '" alt="Loading Image..." />'); 


       $("a.gs-image img").removeClass(); 
       $("a.gs-image img").addClass("gs-image"); 
       $(this).find("img").removeClass(); 
       $(this).find("img").addClass("selectImage"); 

       if ($(".gs-imageResult").length <= 0) { 
        $("#gsearchErr").css("display", "block"); 
       } else { 
        $("#gsearchErr").css("display", "none"); 
       } 

       return false; 
      }); 

      $("div.gsc-cursor").prepend("<div class='clear' style='margin-top:10px;clear:both;'></div>"); 

      $(".gsc-trailing-more-results").css("display", "none"); 

     } 
+0

请提供[jsfiddle示例](http://jsfiddle.net) – Dom 2013-05-07 21:00:18

回答

0

图像检索API结果对象有许多特性。检查the documentation获取完整列表。您可能感兴趣的是url,描述为“将编码的URL提供给结果集中的图像文件。”

值得注意的是,谷歌图片搜索API是正式deprecated in May 2011。如果您正在使用尚未拥有Google Image Search API代码的应用程序,则应该使用较新的Custom Search API