Google site search API (now custom search API since Google site search is shutting down) lets you develop applications to get and show results from Google custom/ site search programmatically. Google site search In this article we will discuss the components of the google site search API and where to find them. Google search for sites has many restrictions and you could sign up for expertrec site search engine using the link below.
Create your custom search engine
Google site search API Call
The usual API call is
https://www.googleapis.com/customsearch/v1?parameters
Google search API query parameters
Here parameters could be –
- q– query string
- cx– Custom search engine ID.
- fileType– bmp, gif, jpg, png, pdf etc
- num-number of search results to display
- searchType- search type.
- sort-Sort by functionality to use.
For a list of all query parameters, go to this link.
GOOGLE SEARCH API SAMPLE API CALL
A sample API call would be like this-
https://www.googleapis.com/customsearch/v1?key={YOUR_API_KEY}&cx={CUSTOM_SEARCH_ENGINE_ID}&q={KEYWORD}
https://www.googleapis.com/customsearch/v1?key=AIzaSyCVAXiUzRYsML1Pvcx=012278024424817052234:cimrvj4h4uk&q=jeff
The response of this API will be in JSON format for you to consume to build your search application.
Getting your API Key
- Go to https://developers.google.com/custom-search/json-api/v1/overview
- Click on the get key.
- Click to create a new project.
- This will generate your new API key.
- You can restrict the usage of this API key in your google API console https://console.developers.google.com/apis
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.
If you are finding issues with the Google site search API, you could try out expertrec’s site search API, which is easier to implement.
Expertrec’s Google site search replacement API-
Go to https://cse.expertrec.com?platform=cse and enter your website and sitemap URLs to get your crawl done. Go and click on your demo link.
Create your custom search engine
- In your demo link open developer tools (control+shift+I) on your chrome browser.
- Go to the network tab.
- Go to the XHR section.
- Search for expertrec.
- Click on searchv7…
The API will be of this format-
https://searchv7.expertrec.com/v6/search/{org_id}/?q={keyword}&page={pagination}&size={number_of_search_results}
https://searchv7.expertrec.com/v6/search/79b96660-27e0-11e8-a8e3-12b6486824f4/?q=a&page=0&size=16
Expertrec site search API parameters-
- org_id- Your unique ID that identifies your website/ websites.
- q- Keyword.
- page- pagination
- size- number of search results to be displayed.
The results will be in JSON format and will be similar to this screenshot-