Forum > Networking and Web Programming

Using Google APIs to launch search from an application


Using the Google Apis package, is it possible to launch search queries and collect responses from an application? If so, as I think, can anyone give me some suggestions? I have already seen the examples provided in the package and I do not seem to have found anything similar. Thanks in advance.

Not as of now as I just tried. The Custom Search API is a rather different beast than other APIs, probably due to its age. I tried converting the calendar demo but the API says it wants the API key parameter, which per Google's own article, should also be possible using OAuth 2.0 but clearly this is not the case.

So, I think you can ignore using that package for now, and do it a little bit more manually:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$mode objfpc}{$H+} uses  opensslsockets,fphttpclient,fpjson,jsonparser; var  SearchResult,ResultItem: TJSONObject;  ResultEnum: TJSONEnum;begin  SearchResult := GetJSON(TFPHTTPClient.SimpleGet('<use yours>&cx=<also use yours>&q=<your query here>')) as TJSONObject;  for ResultEnum in SearchResult.Find('items') do begin    ResultItem := ResultEnum.Value as TJSONObject;    WriteLn(ResultItem['title'].AsString);    WriteLn(ResultItem['link'].AsString);    WriteLn(ResultItem['snippet'].AsString);    WriteLn;  end;  SearchResult.Free;end. You can create the search engine ID (cx parameter) from here while the API key can be created here.

And if somebody is interested in making the demo works, attached is the converted calendar demo project to use TGoogleCustomsearchAPI.

Thank you. I'll try as soon as I can.


[0] Message Index

Go to full version