Google Search API (Single site)
The Google search API is only really useful for searching one site, or a list of related sites. It also has a stingy limit of 100 queries per day, so I guess, Google isn’t really making it easy for people to use it.
Anyway, if those caveats are acceptable, then here’s some code that can be used to query Google in JSON format, once again, this code is designed for Phonegap – or similar trusted environments.
function GoogleSearch(query,callback)
{
var strUrl = “https://www.googleapis.com/customsearch/v1?”;
strUrl += “q=” +encodeURIComponent(query);
strUrl+= “&cx=xxxxxx&key=xxxxxxx”;
$.get(strUrl,function(data)
{
console.log(data);
callback(data);
});
}
The callback from this function can be rendered simply using mustache thus:
<div id=”results”></div>
<script id=”resultsTpl” type=”text/template”>
{{#items}}
<a href=”{{link}}”>{{title}}</a><br>
{{/items}}
</script>
Of course, there’s plenty more data there, but all I needed was the link and title.