A client asked us to fetch Google search results via API for their project. The docs here:

Custom Search JSON API

have the code ready for Javascript. You must of course enter your API key.

The only other point they don’t mention is the parameters for the search call. The ‘q’ parameter is the standard search text. Then the ‘cx’ parameter is required, and that’s the ID of your Google Custom Search Engine. So this line:

return gapi.client.search.cse.list({})

must look more like this:

return gapi.client.search.cse.list({
“cx”: “XXXXXXX”,
“q”: “My Search Text”

With that, it works very well. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *