Google image search says api no longer available
Asked Answered
B

9

94

I am using google image search API. Till yesterday it was working, but today morning it says "This API is no longer available"

Is it officially closed, Or any error at my side

Request

https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q=cute+kittens

Response

{"responseData": null, "responseDetails": "This API is no longer available.", "responseStatus": 403}
Brogue answered 2/12, 2015 at 5:16 Comment(3)
Same thing happened to me. There seems to be no other viable option on the Internet. Thanks Google. superfeedr claims to be able to work but after hours of trying to make sense of their horrible docs there is no way to do what you are doing above. I hope someone implements a solution soon :(Shudder
Gosh, my search engine did not work for 4 entire months until I have discovered this accidentially...Simper
Google should update their Chrome Extension tutorial, as it uses the Google image search. Which, clearly, doesn't work as the tutorial shows it.Exponible
B
4

This is the full URL template to be used

We can eliminate unnecessary parameters.

https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json

I am using

https://www.googleapis.com/customsearch/v1?key=ap_key&cx=cx&q=hello&searchType=image&imgSize=xlarge&alt=json&num=10&start=1

Brogue answered 2/12, 2015 at 9:48 Comment(2)
don't forgtet to put the URL in double quotes.Labyrinth
Searching images is not working. ` { "error": { "code": 500, "message": null } } `Haase
C
141

The answer I found was using Google's Custom Search Engine (CSE) API. Note that this is limited to 100 free requests per day.

Creating cx and modifying it to search for images

  1. Create custom search engine at https://cse.google.com/cse/create/new based on your search criteria.
  2. Choose sites to search (leave this blank if you want to search the entire web, otherwise you can enter a site to search in one particular site)
  3. Enter a name and a language for your search engine.
  4. Click "create." You can now find cx in your browser URL.
  5. Under "Modify your search engine," click the "Control Panel" button. In the "edit" section you will find an "Image Search" label with an ON/OFF button, change it to ON. Click "update" to save your changes.

Conducting a search with the API

The API endpoint url is https://www.googleapis.com/customsearch/v1

The following JSON parameters are used for this API:

  • q: specifies search text
  • num: specifies number of results. Requires an integer value between 1 and 10 (inclusive)
  • start: the "offset" for the results, which result the search should start at. Requires an integer value between 1 and 101.
  • imgSize: the size of the image. I used "medium"
  • searchType: must be set to "image"
  • filetype: specifies the file type for the image. I used `"jpg", but you can leave this out if file extension doesn't matter to you.
  • key: an API key, obtained from https://console.developers.google.com/
  • cx: the custom search engine ID from the previous section

Simply make a GET request by passing above parameters as JSON to the API endpoint (also listed above).

Note: If you set a list of referrers in the search engine settings, visiting the URL via your browser will likely not work. You will need to make an AJAX call (or the equivalent from another language) from a server specified in this list. It will work for only the referrers which were specified in the configuration settings.

Reference: https://developers.google.com/custom-search/json-api/v1/reference/cse/list

Culm answered 3/12, 2015 at 9:38 Comment(7)
This is a good solution, but note there is a quota on this API. 100 queries per day for free. After that $5 per 1,000 queries. Even with billing enabled, you cannot exceed 10,000 queries per day, at a maximum rate of 1 query per second.Outbuilding
Remember to select "site to search". "Search the entire web but emphasize included sites"Instruct
You need to enter something under Image.org types under Advanced before it will let you create the custom search engine. You can then remove the tag when you turn on image search.Exponible
What about searching for images by an image you upload?Opulent
@Opulent You can do something like that using the Vision API.Disreputable
Google now require you to put in a site to search: "You must enter at least one site or schema before creating a search engine."Javed
@Javed (& Everybody else...) Apparently they have buried the option for searching the entire web in the 'Setup' menu. So you can create a custom search engine for a random domain, save it, and then go to 'Edit > Setup', delete the domain and enable 'Search the entire web'.Volcanic
A
30

Now You can search images with Custom image search API.

You can do this with two steps:

  1. Get CUSTOM_SEARCH_ID

Go to - https://cse.google.ru/cse/all

Here you must create new Search Engine. Do this and enable Image Search at there.

Screen(i am Russian... sorry)

image search enable

then get this search engine ID. To do this press at Get Code button:

get code button

And there find line with cx = "here will be your CUSTOM_SEARCH_ID":

get CSE id

Ok. It's done, now second step:

  1. Get SERVER_KEY

Go to google Console - https://console.developers.google.com/project

Google API Console

Press to Create project button, enter the name and other required information. Pick this project and go to Enable Apis project dashboard Now find Custom Search Engine.

custom SE find And Enable it.

Enable Custom Search

Now we must go to Credentials and create new Server Key:

Create server Key

Ok. Now we can use Image Search.

Query:

https://www.googleapis.com/customsearch/v1?key=SERVER_KEY&cx=CUSTOM_SEARCH_ID&q=flower&searchType=image&fileType=jpg&imgSize=xlarge&alt=json

Replace the SERVER_KEY and CUSTOM_SEARCH_ID and call this request.

Limit: for free you can search only 100 images per day.

Arbiter answered 10/3, 2016 at 17:9 Comment(0)
L
10

If this is just for your own purposes (not for production) and you're not planning to abuse Google Image Search, you can simply extract first image URL from Google search results using JSOUP.

For example: Code to retrieve image URL of the first thumbnail:

public static String FindImage(String question, String ua) {
            String finRes = "";

    try {
            String googleUrl = "https://www.google.com/search?tbm=isch&q=" + question.replace(",", "");
            Document doc1 = Jsoup.connect(googleUrl).userAgent(ua).timeout(10 * 1000).get();
            Element media = doc1.select("[data-src]").first();
            String finUrl = media.attr("abs:data-src"); 

            finRes= "<a href=\"http://images.google.com/search?tbm=isch&q=" + question + "\"><img src=\"" + finUrl.replace("&quot", "") + "\" border=1/></a>";

        } catch (Exception e) {
            System.out.println(e);
        }

        return finRes;
    }

Guide:

question - image search term

ua - user agent of the browser

Liquidity answered 6/12, 2015 at 2:34 Comment(0)
S
10

After I read several responses I compiled a response with images:

  1. Access the website: https://developers.google.com/custom-search/v1/introduction, on the page you will find this part, so click in the button Get a Key:

Page to get a key

  1. Create or select a project, and then NEXT:

Select a project, or create a one

  1. Copy the API KEY:

Copy the API KEY

  1. Access the website to create your CX: https://cse.google.com/cse/create/new, write some random domain like “www.anypage.com”, (after we will delete), select a language, and define some name for your search engine. Click on the Button CREATE.

Creating your CX

  1. Will see this page, then click in Control Panel:

Control Panel

  1. Copy the Search engine ID for later (this is your CX). After you can set to search in all websites (active Search the entire web, select on the random website www.anypage.com then click on the button Delete) and you can active Image search. So will see like this:

Settings Controle Panel

  1. And Using REST you can get the results, using this example code (searching for flower):
<html lang="pt">
<head>
    <title>JSON Custom Search API Example</title>
</head>
<body>
    <div id="content"></div>
    <script>
        function hndlr(response) {
            console.log(response);
            for (var i = 0; i < response.items.length; i++) {
                var item = response.items[i];
                // in production code, item.htmlTitle should have the HTML entities escaped.
                document.getElementById("content").innerHTML += "<br>" + item.htmlTitle;
            }
        }
    </script>
    <script src="https://www.googleapis.com/customsearch/v1?key=API_KEY&cx=SEARCH_ENGINE_KEY&q=flower&searchType=image&callback=hndlr"></script>
</body>
</html>

The base code is found here: https://developers.google.com/custom-search/v1/using_rest

  1. After setting your API_KEY (key) and your SEARCH ENGINE KEY (cx), the result will see like this:

Result

Thanks to @Vijay Shegokar, @aftamat4ik and @Alladinian

Swatch answered 29/6, 2020 at 5:14 Comment(0)
B
4

This is the full URL template to be used

We can eliminate unnecessary parameters.

https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json

I am using

https://www.googleapis.com/customsearch/v1?key=ap_key&cx=cx&q=hello&searchType=image&imgSize=xlarge&alt=json&num=10&start=1

Brogue answered 2/12, 2015 at 9:48 Comment(2)
don't forgtet to put the URL in double quotes.Labyrinth
Searching images is not working. ` { "error": { "code": 500, "message": null } } `Haase
C
3

Change the API url to Google Custom Image search

Provide the same parameters along with with API KEY and CX.

More Info and Explorer

Cudbear answered 2/12, 2015 at 7:33 Comment(3)
The new google API will let you use only 100 req per day ! why ! it was the best :( !! google needs moneyIngaborg
you can do more than 100, but not for freeLilithe
I can only think of free searches :)Cudbear
O
0

The Yahoo Boss API is a reasonable substitute, although it's not free and the results are not quite as good.

UPDATE: YAHOO BOSS JSON Search API will discontinue on March 31, 2016

Outbuilding answered 3/12, 2015 at 20:34 Comment(0)
F
-1

SerpAPI enables to search through Google Images and returns a clean json. it integrates with most of the programming languages: python, php, java, golang, nodejs...

https://serpapi.com/images-results

Google limit the number of search per day. but this service provides unlimited searches...

Forearm answered 5/12, 2018 at 2:15 Comment(0)
R
-2

looks like we need to implement google custom search API https://developers.google.com/custom-search/ says so on top of the page you provided yourself

Rigsdaler answered 2/12, 2015 at 16:53 Comment(1)
please review your answer, doesn't seem to be rightFerrotype

© 2022 - 2024 — McMap. All rights reserved.