0

I have been trying to use google custom search api so i can download pictures from it and allow users to use it as their "cover" photo. Is this even possible? I can get image search results but they seem to only be thumb nail size:

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");

        }
anthonypliu
  • 12,179
  • 28
  • 92
  • 154

1 Answers1

0

The result object from the image search API has many properties. Check the documentation for a complete list. The property you would be interested in is url, described as "Provides the encoded URL to an image file in the result set."

It's worth noting that the Google Image Search API was officially deprecated in May 2011. If you're working on an application that doesn't already have a legacy of Google Image Search API code, you should instead use the newer Custom Search API.

Snixtor
  • 4,239
  • 2
  • 31
  • 54