Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google results in XML/JSON - using the Custom Search Engine

Tags:

xml

google-api

I'm having difficulty figuring out the right format for URL calls to a Google Custom Search Engine (CSE) to return results in XML (using their free service for 100 calls per day). I've set up an account and CSE. So now I have a public URL https://www.google.com/cse/publicurl?cx=010317493064298903457:5bsx2whinf8 to search BBC news. But I can't figure out from the documentation how to develop the URL call to return results in XML format..

https://www.google.com/cse/publicurl?cx=010317493064298903457:5bsx2whinf8&q=lon‌​don&start=0&num=10&output=xml_no_dtd (based on the code provided in the CSE setup options) gives results in html frame.

http://www.google.com/search?start=0&num=10&q=london&client=google-csbe&output=‌​xml_no_dtd&cx=010317493064298903457:5bsx2whinf8 (following the XML API examples) also returns HTML.

Very grateful for an idea where I'm going wrong.

like image 788
geotheory Avatar asked Dec 09 '22 08:12

geotheory


1 Answers

Cracked. The minimum working URL formula I've got to work is a concatenation of the following strings:

  • "https://www.googleapis.com/customsearch/v1?"
  • "q=" + search terms (e.g. "London+UK")
  • "&cx=" + cx code of your CSE
  • "&key=" + your authorised API key [create an API project, then go to 'APIs & auth' and activate in 'Custom Search API']

You should end up with something looking like this:

"https://www.googleapis.com/customsearch/v1?q=London+UK&cx=018475493028468909364:ldifwlodnso&key=AOgsDiRlzY7GDCKC5Th7yKutv-7Hd4-IDehl_Sp"

.. with results in json.

like image 189
geotheory Avatar answered Jan 07 '23 23:01

geotheory