Google Search Programmatically

Google Custom Search Programmatically

Using JSON/Atom Custom Search API, you can use RESTful requests to get either web search or image search results in JSON or Atom format.

Pricing options for Google Custom Search
JSON/Atom Custom Search API pricing and quotas depend on the engine’s edition:

  1. Custom Search Engine (free): For CSE users, the API provides 100 search queries per day for free. If you need more, you may sign up for billing in the Cloud Console. Additional requests cost $5 per 1000 queries, up to 10k queries per day.
  2. Google Site Search (paid): For detailed information on GSS usage limits and quotas, please check GSS pricing options.

Prerequisites for Google Custom Search
For performing google search through a program, you will need a developer api key and a custom search engine id.

How to get Google Developers API key?
Step 1: Log in to Google Developers Console with your google id (gmail).
Step 2: Create a project. Click on create project.
google search programatically
Step 3: Enter Project Name. Check the agreement check box and click on create.
google search programatically-1
Step 4: Now you can see the Project dashboard of newly created project. Now click on APIs & auth ->auth. Switch on the Custom Search API, by default it is off.
google search programatically-2
Step 5: Click on Credentials -> Create New Key (under Public api access)
google search programatically-3
Step 6: Click on Server key.
google search programatically-4
Step 7: Save your API key in notepad.
google search programatically-5
How to create Google Custom Search Engine?
Google Custom Search by Google allows web developers to include google search box in their web pages. The search box can be configured to search their own website or any other website they are configured to search.
Step 1: Log in to Google Custom Search
Step 2: Select New Search Engine
Step 3: Now you can enter the websites to be searched using google custom search. You can also include entire domains instead of specific websites as shown below.
google search programatically-6
Step 4: Click on create. It will show you below Screen.
google search programatically-7
Step 5: Click on get Code, note down the code (cx=xxxxx). If you want Google search box in you blog or website, you can copy paste the below script directly to your website.
google search programatically-8
Step 6: Your URL will look like below with search string “BasicsBehind”
google custom search

Google Search Programmatically using JAVA

You can add other parameters to Google search with ‘&’ operator, for example lr=lang_en restricts the search to documents written in a English language.
You can find complete list of parameters here:-
Parameters to pass with the search query to filter the results:
Language and country codes to pass with query:

  • Excellent, never thought of this kind of API. Very useful, thanks for sharing! :-)