Home PHP JavaScript CSS WordPress APIs .htaccess Other How-To Useful Scripts What I Recommend
Posted on by Aleksandar Gichevski ()
Have you noticed that when you start typing in Google search box the system tries to guess what you are searching and gives you instantly few suggestions that you can choose from. In most of the cases Google has the right answer which makes this feature very nice and helpful for the visitors. Good news is that if you want you can implement same functionality in your website. There isn't any documented API how to do this but if you look little outside the box you can see that the suggestions feature is not protected and it can be used very easy. In this post I cover all the aspects of Google Autocomplete API. I gathered in one place all information needed for using this service and also will show you quick php example how you can get in real time, suggestions directly from Google.

google-autocomplete-api

Get Suggestions using Google AutoComplete API

Getting suggestions directly from Google is done by sending specific GET parameters to following URL:

http://suggestqueries.google.com/complete/search

Here is a table of the necessary parameters that need to be used:
Parameter Status Description Accepted Values
hl Optional (default is en) Defines the language in which the search is being performed. Any Google Language Code (you can see all codes here )
client Required Defines the format of the returned data. firefox - JSON

toolbar - XML

youtube - JSONP
q Required Your search term that you want to get suggestions for. Search term.
ds Optional (default is google search) Choose the site you want to target Google or YouTube. For YouTube use
ds = yt
jsonp Optional (default is window.google.ac.h) Name of the JSONP callback function. Your JSONP callback function
Based on the above information here are google autocomplete api examples for all 3 data formats: JSON: http://suggestqueries.google.com/complete/search?client=firefox&q=top+so XML: http://suggestqueries.google.com/complete/search?client=firefox&q=top+so JSONP: http://suggestqueries.google.com/complete/search?client=firefox&q=top+so

Google AutoComplete API Example

Here is quick php code for getting google suggestions data and parsing it into array for further use:


If you want to get data instantly without server code use JSONP, if you are not familiar with it here is tutorial for Ajax where you can combine server and client code in order to get same results.






Other Posts You Might Like

Get a fast, free website audit

Enter your URL below to get full in-depth SEO report and tips.

‚Äč

Useful Scripts

Most Popular Posts

Recent Posts

June 14th, 2014
Website Optimization Using Gzip Compression

June 10th, 2014
Google Search AutoComplete API

May 14th, 2014
What is a Tag Cloud and How to Calculate it by Formula

March 27th, 2014
Error writing file /tmp (errcode 28) Solved!

February 15th, 2014
Fixed CSS & HTML Navigation Bar

February 9th, 2014
Benchmark Your Server (CPU, File IO, MySQL) with SysBench

February 8th, 2014
JavaScript Array Basics

January 29th, 2014
JVZoo IPN API in PHP

January 25th, 2014
Payoneer Debit Card for Freelancers to receive money online

January 24th, 2014
How HTML Color Codes are generated?

Read Latest Posts directly on Facebook

Archive

X

Get a fast, free website audit

Enter your URL below to get full in-depth SEO report and tips.