Google Search by Image API

Google hasn’t officially released its new search by image API so I thought of researching and writing a small article on how one can use this searching technique in their custom web, desktop and mobile apps.

Here’s a quick analysis first. Basically you replicate what the browser does for you and scrape the response.

Search Location:

Request Headers:
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Cookie: PREF=ID=1d7bc4ff2a5d8bc6:U=1d37ba5a518b9be1:FF=4:LD=en:TM=1300950025:LM=1302071720:S=rkk0IbbhxUIgpTyA; NID=51=uNq6mZ385WlV1UTfXsiWkSgnsa6PdjH4l9ph-vSQRszBHRcKW3VRJclZLd2XUEdZtxiCtl5hpbJiS3SpEV7670w_x738h75akcO6Viw47MUlpCZfy4KZ2vLT4tcleeiW; SID=DQAAAMEAAACoYm-3B2aiLKf0cRU8spJuiNjiXEQRyxsUZqKf8UXZXS55movrnTmfEcM6FYn-gALmyMPNRIwLDBojINzkv8doX69rUQ9-

You can ignore most of the above and use standard HTTP headers of a normal browser or CURL it.

What’s important is the multipart form data which gets posted to the Search Location Above:



















The HTML form below posts everything for you, results of which you could scrap and use it for your app.

<form action = “” METHOD=”POST” enctype=”multipart/form-data”>
<input type =”file” name = “encoded_image”>
<input type=”Submit” name = “Search” value = “Search”>
<input type = “hidden” name = “h1″ value =”en”>
<input type = “hidden” name = “safe” value =”off”>
<input type = “hidden” name = “bih” value =”800″>
<input type = “hidden” name = “biw” value =”1280″>
<input type = “hidden” name = “image_content” value =”">
<input type = “hidden” name = “filename” value =”">