Google Custom Search Site Restricted JSON API

Google Custom Search Site Restricted JSON API help

Rate this article

Share this article

In this article, we will see how to use the Google custom search site restricted JSON API. For people looking to skip coding and directly implement a search for their websites, go herecustom search site restricted json api

Custom Search Engine offers very similar functionality to the Google Site Search but comes with a major disadvantage: ads. If you’re not a nonprofit or school then you’ll be stuck with ads. On the plus side, you can monetize the ads by connecting your Adsense account, but you’ll still likely be advertising for competitors. You can try search engines other than google that don’t track you

Custom Search Site Restricted JSON API  intro

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-

https://www.googleapis.com/customsearch/v1/siterestrict?[parameters]

 

Query parameters

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-

custom search site restricted json api

On-site search is a crucial feature on a website. When your visitors are on your website, no matter how they arrived, they might want to explore more. Of course, a popular posts widget on the sidebar or related posts listed under every blog post will help them read more content and stay on your site for a long time. But what if they are looking for something really specific on your website? Learn how to add a search bar to your website in HTML

Sample API Call

Here is a sample api call to get search results-

https://www.googleapis.com/customsearch/v1/siterestrict?key={your_api_key}&cx={custom_search_engine_id}&q={search_keyword}

 

https://www.googleapis.com/customsearch/v1/siterestrict?key=AIzaSyDOvbipdULbUpVm3HLjoX7bEEfDUKHELh4&cx=012278024424817052234:cimrvj4h4uk&q=linkedin

Search results in JSON format

Here are the search results in JSON format-

{
   "kind": "customsearch#result",
   "title": "LinkedIn: Log In or Sign Up",
   "htmlTitle": "\u003cb\u003eLinkedIn\u003c/b\u003e: Log In or Sign Up",
   "link": "https://www.linkedin.com/",
   "displayLink": "www.linkedin.com",
   "snippet": "500 million+ members | Manage your professional identity. Build and engage \nwith your professional network. Access knowledge, insights and opportunities.",
   "htmlSnippet": "500 million+ members | Manage your professional identity. Build and engage \u003cbr\u003e\nwith your professional network. Access knowledge, insights and opportunities.",
   "cacheId": "AszVZRcWxZEJ",
   "formattedUrl": "https://www.linkedin.com/",
   "htmlFormattedUrl": "https://www.\u003cb\u003elinkedin\u003c/b\u003e.com/",
   "pagemap": {
    "metatags": [
     {
      "referrer": "origin",
      "pageimpressionid": "b502334b-1c2a-442a-b05b-6883abbfb21b",
      "appname": "chrome",
      "pagekey": "uno-reg-guest-home",
      "treeid": "bjU+kvwgSRWw0apPLysAAA==",
      "globaltrackingurl": "//www.linkedin.com/mob/tracking",
      "globaltrackingappname": "chrome",
      "globaltrackingappid": "webTracking",
      "msapplication-tileimage": "https://static.licdn.com/scds/common/u/images/logos/linkedin/logo-in-win8-tile-144_v1.png",
      "msapplication-tilecolor": "#0077B5",
      "application-name": "LinkedIn",
      "remotenavjscontentbaseurl": "https://static.licdn.com/scds/concat/common/js?v=0.1.561",
      "lnkd-track-json-lib": "https://static.licdn.com/scds/concat/common/js?h=2jds9coeh4w78ed9wblscv68v-ebbt2vixcc5qz0otts5io08xv",
      "apphost": "seo-directory-frontend",
      "appversion": "0.1.343",
      "appinstance": "i002",
      "locale": "en_US",
      "baidu-site-verification": "bqQqxRHTnv",
      "detectadblock": "//platform.linkedin.com/js/px.js"
     }

Adding a search box to a website can quickly get tricky if not done right. Developing a search engine from scratch is never a good idea keeping in mind the cost and quality. Google’s own solution to this was GSS which got shut down and replaced by Google Custom Search. You can learn how to Google search specific website

Getting your custom search API Key-

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.

custom search site restricted json api

 

Testing with Google API explorer

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

custom search site restricted json api

Read more on google search script

 

Expertrec’s Google custom search replacement API to overcome google custom search limitations

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.

Add Search to your Website

Go to https://cse.expertrec.com/csedashboard/home/Status to get your API keycustom search site restricted json api

A static website with a dynamic search function? Yes, Hugo provides an alternative to embeddable scripts from Google or other search engines for static websites. Check out hugo themes with search

Expertrec custom search API format

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-

  1. org_id- Your unique ID that identifies your website/ websites.
  2. q- Keyword.
  3. page- pagination
  4. size- number of search results to be displayed.

The results will be in JSON format and will be similar to this screen shot-

{  
   "0len":1,
   "1query":"a",
   "facet_interval":{  

   },
   "facets":{  
      "type":{  
         "webpage":160
      }
   },
   "fq":{  

   },
   "nf":{  

   },
   "numeric":{  

   },
   "res":{  
      "count":160,
      "st":0,
      "time":3
   },
   "results":[  
      {  
         "date":"2018-05-09T12:35:47.110Z",
         "host":"blog.expertrec.com",
         "id":"https://blog.expertrec.com/wordpress-custom-search/",
         "image":[  
            "https://blog.expertrec.com/wp-content/uploads/2018/04/6.png"
         ],
         "popularity_score":1.0,
         "score":1.25,
         "snippet":{  
            "content":[  
               "How&#32;to&#32;<span class=highlight>create</span>&#32;<span class=highlight>a</span>&#32;wordpress&#32;custom&#32;<span class=highlight>search</span>&#32;&#45;&#32;2018&#32;Expertrec&#10;&#160;&#10;Support&#10;<span class=highlight>magento</span>&#10;<span class=highlight>search</span>&#32;engine&#10;Google&#32;site&#32;<span class=highlight>search</span>&#32;<span class=highlight>replacement</span>&#10;Expertec&#10;Toggle&#32;<span class=highlight>Navigation</span>&#10;How&#32;to&#32;<span class=highlight>create</span>&#32;<span class=highlight>a</span>&#32;wordpress&#32;custom&#32;<span class=highlight>search</span>&#10;Published&#32;by&#32;<span class=highlight>muthali</span>&#32;<span class=highlight>ganesh</span>&#32;on&#32;<span class=highlight>April</span>&#32;8&#44;&#32;2018&#10;<span class=highlight>Creating</span>&#32;wordpress&#32;custom&#32;<span class=highlight>search</span>&#32;using&#32;expertrec&#32;is&#32;<span class=highlight>as</span>&#32;<span class=highlight>easy</span>&#32;<span class=highlight>and</span>&#32;<span class=highlight>can</span>&#32;be&#32;<span class=highlight>taken</span>&#32;live&#32;in&#32;5&#32;minutes&#46;&#32;"
            ],
            "metatag.description":[  

            ],
            "title":[  
               "How&#32;to&#32;<span class=highlight>create</span>&#32;<span class=highlight>a</span>&#32;wordpress&#32;custom&#32;<span class=highlight>search</span>&#32;&#45;&#32;2018&#32;Expertrec"
            ]
         },
         "title":"How to create a wordpress custom search - 2018 Expertrec",
         "type":"webpage",
         "url":"https://blog.expertrec.com/wordpress-custom-search/"
      }
   ],
   "sfacets":{  
      "type":[  
         {  
            "count":160,
            "name":"webpage"
         }
      ]
   }
}

 

 

Add Search to your Website

Did you know that the default WordPress search engine isn’t really that efficient (and awesome) as the rest of WordPress? Check out here how you can get WordPress advanced search plugin.

Google search script for sites is an easy and effective way to add search capabilities to your site. You can learn more about Google custom search JS examples

You can try how to turn off Ads in Google search to remove ads in GCS.

If your Google site search is not working you can refer Google custom search support to find a solution. 

Looking for how to add multiple websites in google custom search include sites in bulk

Sometimes you might want to see more than ten results on the Google SERP (Search Engine Results Page). Increasing the result count per page is pretty simple. You can read google custom search pagination to know how

You can also try searching multiple websites at once

 

Are you showing the right products, to the right shoppers, at the right time? Contact us to know more.
You may also like