首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在我的google图片搜索中没有图片

在我的google图片搜索中没有图片
EN

Stack Overflow用户
提问于 2015-10-30 16:00:59
回答 2查看 601关注 0票数 2

好吧,我想使用google api进行图像搜索,我知道这是不推荐使用的,但我不想使用自定义搜索

这是我一直使用的代码

代码语言:javascript
复制
<script type="text/javascript">

  google.load('search', '1');

  var imageSearch;

  function addPaginationLinks() {

    // To paginate search results, use the cursor function.
    var cursor = imageSearch.cursor;
    var curPage = cursor.currentPageIndex; // check what page the app is on
    var pagesDiv = document.createElement('div');
    for (var i = 0; i < cursor.pages.length; i++) {
      var page = cursor.pages[i];
      if (curPage == i) { 

      // If we are on the current page, then don't make a link.
        var label = document.createTextNode(' ' + page.label + ' ');
        pagesDiv.appendChild(label);
      } else {

        // Create links to other pages using gotoPage() on the searcher.
        var link = document.createElement('a');
        link.href="/image-search/v1/javascript:imageSearch.gotoPage("+i+');';
        link.innerHTML = page.label;
        link.style.marginRight = '2px';
        pagesDiv.appendChild(link);
      }
    }

    var contentDiv = document.getElementById('content');
    contentDiv.appendChild(pagesDiv);
  }

  function searchComplete() {

    // Check that we got results
    if (imageSearch.results && imageSearch.results.length > 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 = imageSearch.results;
      for (var i = 0; i < 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('div');

        // 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="/image-search/v1/result.tbUrl;"
        imgContainer.appendChild(title);
        imgContainer.appendChild(newImg);

        // Put our title + image in the content
        contentDiv.appendChild(imgContainer);
      }

      // Now add links to additional pages of search results.
      addPaginationLinks(imageSearch);
    }
  }

  function OnLoad() {

    // Create an Image Search instance.
    imageSearch = new google.search.ImageSearch();

    // Set searchComplete as the callback function when a search is 
    // complete.  The imageSearch object will have results in it.
    imageSearch.setSearchCompleteCallback(this, searchComplete, null);

    // Find me a beautiful car.
    imageSearch.execute("Ferrari");

    // Include the required Google branding
    google.search.Search.getBranding('branding');
  }
  google.setOnLoadCallback(OnLoad);
</script>

问题是,当我运行它时,图像不会出现

我知道问题在于它使用的url不起作用。

问题是这行代码

代码语言:javascript
复制
newImg.src="/image-search/v1/result.tbUrl;"

但是我不知道是否有其他的url可以使用,或者我能做些什么。

我不能使用JQuery,这是一个大学项目,我们也不能使用JQuery

感谢您的关注!

EN

回答 2

Stack Overflow用户

发布于 2016-01-23 19:17:43

Google Image Search API已于2011年5月26日正式弃用,显然已完全停用。

返回callback google.search.ImageSearch.RawCompletion('1', null, 403, 'This API is no longer available.', 200)的GimageSearch上的XHR调用

您必须使用新的自定义搜索API:https://developers.google.com/custom-search/

票数 0
EN

Stack Overflow用户

发布于 2015-10-30 16:28:14

变化

代码语言:javascript
复制
link.href="/image-search/v1/javascript:imageSearch.gotoPage("+i+');';

代码语言:javascript
复制
link.href="javascript:imageSearch.gotoPage("+i+');';

和改变

代码语言:javascript
复制
newImg.src="/image-search/v1/result.tbUrl;"

代码语言:javascript
复制
newImg.src=result.tbUrl;
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33431195

复制
相关文章

相似问题

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