简体   繁体   English

无法获取图片的原始网址

[英]Cant get original URL of image

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. 我一直在尝试使用Google自定义搜索API,因此我可以从中下载图片,并允许用户将其用作其“封面”照片。 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");

        }

The result object from the image search API has many properties. 图像搜索API的结果对象具有许多属性。 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." 您可能感兴趣的属性是url ,它描述为“在结果集中为图像文件提供编码的URL”。

It's worth noting that the Google Image Search API was officially deprecated in May 2011 . 值得注意的是,Google Image Search API已于2011年5月正式弃用 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 . 如果您正在使用的应用程序尚未具有旧版的Google Image Search API代码,则应改用较新的Custom Search API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM