Using google custom search api, you can programatically generate search generate google custom search results. google custom search api

There are two types of google custom search apis-

  1. Google custom search JSON API
  2. Google Custom Search Site Restricted JSON API

——————————————————————————————————————————————————–

Google custom search JSON API-

Google custom search JSON API is a RESTFUL API lets you develop applications to get and show search results (websearch, images) from Google custom search programatically. With this API, you can use RESTful requests to get either web search or image search results in JSON format.

The existing documentation on creating a google custom search using the api method is confusing and we will try to simplify the process here.

In this article we will see how we can create a custom search engine using the Google custom search api . We will also see what are the limitations of google custom search api and how we can over come them.

Create your custom search engine using expertrec

Create a custom search engine at https://www.google.com/cse

The usual API call is

Here parameters could be –

  1. q– query string
  2. cx– Custom search engine ID.
  3. fileType– bmp, gif, jpg, png, pdf etc
  4. num-number of search results to display
  5. searchType- search type.
  6. sort-Sort by functionality to use.

For a list of all query parameters, go to this link.

Google custom search JSON API simplified

A sample api call would be like this-

Response of this API will be in JSON format for you to consume to build your search application.

Getting your google custom search API Key

  1. Go to https://developers.google.com/custom-search/json-api/v1/overview
  2. Click on get  a key.Google custom search JSON API simplified
  3. Click create new project.Google custom search JSON API simplified
  4. This will generate your new API key.Google custom search JSON API simplified
  5. You can restrict the usage of this API key in your google api console https://console.developers.google.com/apis

Google custom search JSON API simplified

Getting your CX / Search engine ID:

Go to your custom search / site search control panel-> edit search engine->Basics->Details->Search engine ID.

This is your search engine ID.

Google custom search JSON API simplified

Testing your google custom search JSON API-

You can test you google custom search api using the google api explorer 

google custom search JSON simplified———————————————————————————————————————————————————Google custom search site restricted API-

google custom search site restricted json api

Points to remember- (if you do not adhere to the following points your API might not return the search results)

  1. Google Custom Search Site Restricted JSON API is similar to the JSON custom search API.
  2. You can search within 10 or lesser websites using this API.
  3. No daily Query limit.
  4. Make sure that the “search the entire web” is set to OFF.

Create your google custom search from https://cse.google.com

Google Custom Search Site Restricted JSON API is of the following format-

Here parameters could be –

  1. q– query string
  2. cx– Custom search engine ID.
  3. fileType– bmp, gif, jpg, png, pdf etc
  4. num-number of search results to display
  5. searchType- search type.
  6. sort-Sort by functionality to use.

Here are the list of all parameters-

google custom search site restricted json api

Here is a sample api call to get search results-

Here are the search results in JSON format-

How to get your custom search API Key-

  1. Go to https://developers.google.com/custom-search/json-api/v1/overview
  2. Click on get  a key.
  3. Click create new project.
  4. This will generate your new API key.google custom search site restricted json api

Getting your CX / Search engine ID:

Go to your custom search / site search control panel-> edit search engine->Basics->Details->Search engine ID.

You can test you google custom search api using the google api explorer 

 

 

 


muthali ganesh

Muthali loves writing about emerging technologies and easy solutions for complex tech issues. You can reach out to him through chat or by raising a support ticket on the left hand side of the page.