首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法获取图像的原始URL

无法获取图像的原始URL
EN

Stack Overflow用户
提问于 2013-05-08 02:42:56
回答 1查看 398关注 0票数 0

我一直在尝试使用google自定义搜索api,这样我就可以从它下载图片,并允许用户使用它作为他们的“封面”照片。这有可能吗?我可以得到图片搜索结果,但它们似乎只有拇指指甲大小:

代码语言:javascript
复制
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");

        }
EN

回答 1

Stack Overflow用户

发布于 2013-05-08 05:36:06

来自图像搜索API的结果对象具有许多属性。有关完整的列表,请查看the documentation。您可能感兴趣的属性是url,描述为“为结果集中的图像文件提供编码的URL”。

值得注意的是,Google Image Search API的官方名称是deprecated in May 2011。如果您正在使用的应用程序还没有Google Image Search API的遗留代码,那么您应该使用较新的Custom Search API

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16426301

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档