2006-08-26 00:35:42 +00:00
|
|
|
program test_google_api;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
uses
|
|
|
|
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
|
|
|
cthreads,
|
|
|
|
{$ENDIF}{$ENDIF}
|
|
|
|
Classes, SysUtils,
|
|
|
|
base_service_intf, service_intf, soap_formatter,
|
|
|
|
//indy_http_protocol,
|
|
|
|
ics_http_protocol,
|
|
|
|
synapse_http_protocol,
|
2006-11-12 13:31:22 +00:00
|
|
|
googlewebapi, googlewebapi_proxy, wst_resources_imp;
|
2006-08-26 00:35:42 +00:00
|
|
|
|
|
|
|
Const
|
2006-10-29 01:50:19 +00:00
|
|
|
//sADRESS = 'http:Address=http://api.google.com/search/beta2;Proxy';
|
|
|
|
sADDRESS = 'http:Address=http://api.google.com/search/beta2'+
|
|
|
|
';ProxyServer=10.0.0.5;ProxyPort=8080';
|
2006-08-26 00:35:42 +00:00
|
|
|
sTARGET = 'urn:GoogleSearch';
|
2007-03-23 23:22:35 +00:00
|
|
|
sKEY = '<your key here>';
|
2006-08-26 00:35:42 +00:00
|
|
|
sSERVICE_PROTOCOL = 'SOAP';
|
|
|
|
Var
|
|
|
|
tmpObj : IGoogleSearch;
|
|
|
|
qryRes : TGoogleSearchResult;
|
|
|
|
strBuffer : string;
|
|
|
|
i , c: Integer;
|
|
|
|
resElt : TResultElement;
|
|
|
|
resDir : TDirectoryCategory;
|
|
|
|
begin
|
|
|
|
//ICS_RegisterHTTP_Transport();
|
|
|
|
SYNAPSE_RegisterHTTP_Transport();
|
|
|
|
//INDY_RegisterHTTP_Transport();
|
|
|
|
WriteLn();
|
|
|
|
WriteLn('Enter phrase to spell :');
|
|
|
|
ReadLn(strBuffer);
|
2006-10-29 01:50:19 +00:00
|
|
|
tmpObj := TGoogleSearch_Proxy.Create(sTARGET,sSERVICE_PROTOCOL,sADDRESS);
|
2006-08-26 00:35:42 +00:00
|
|
|
Try
|
|
|
|
strBuffer := tmpObj.doSpellingSuggestion(sKEY,strBuffer);
|
|
|
|
WriteLn('google spell >>> ',strBuffer);
|
|
|
|
Except
|
|
|
|
On E : Exception Do
|
|
|
|
WriteLn(E.Message);
|
|
|
|
End;
|
|
|
|
|
|
|
|
WriteLn();
|
|
|
|
WriteLn('Enter phrase to search :');
|
|
|
|
ReadLn(strBuffer);
|
|
|
|
Try
|
|
|
|
qryRes := tmpObj.doGoogleSearch(sKEY,strBuffer,0,10,True,'',False,'','latin1','latin1');
|
|
|
|
Try
|
|
|
|
WriteLn('---------------------------------------');
|
|
|
|
WriteLn('google Search >>');
|
|
|
|
WriteLn('documentFiltering = ',qryRes.documentFiltering);
|
|
|
|
WriteLn('startIndex = ',qryRes.startIndex);
|
|
|
|
WriteLn('endIndex = ',qryRes.endIndex);
|
|
|
|
WriteLn('estimatedTotalResultsCount = ',qryRes.estimatedTotalResultsCount);
|
|
|
|
WriteLn('estimateIsExact = ',qryRes.estimateIsExact);
|
|
|
|
WriteLn('searchComments = ',qryRes.searchComments);
|
|
|
|
WriteLn('searchQuery = ',qryRes.searchQuery);
|
|
|
|
WriteLn('searchTime = ',qryRes.searchTime);
|
|
|
|
WriteLn('searchTips = ',qryRes.searchTips);
|
|
|
|
|
|
|
|
WriteLn('-------------------------------------------');
|
|
|
|
WriteLn('directoryCategories >>');
|
|
|
|
WriteLn(' Length = ',qryRes.directoryCategories.Length);
|
|
|
|
c := qryRes.directoryCategories.Length;
|
|
|
|
For i := 0 To Pred(c) Do Begin
|
|
|
|
resDir := qryRes.directoryCategories[i];
|
|
|
|
WriteLn('');
|
|
|
|
WriteLn('Item[',i,'] >>');
|
|
|
|
WriteLn(' fullViewableName = ',resDir.fullViewableName);
|
|
|
|
WriteLn(' specialEncoding = ',resDir.specialEncoding);
|
|
|
|
End;
|
|
|
|
|
|
|
|
WriteLn('-------------------------------------------');
|
|
|
|
WriteLn('resultElements >>');
|
|
|
|
WriteLn(' Length = ',qryRes.resultElements.Length);
|
|
|
|
c := qryRes.resultElements.Length;
|
|
|
|
For i := 0 To Pred(c) Do Begin
|
|
|
|
resElt := qryRes.resultElements[i];
|
|
|
|
WriteLn('');
|
|
|
|
WriteLn('Item[',i,'] >>');
|
|
|
|
WriteLn(' cachedSize = ',resElt.cachedSize);
|
|
|
|
WriteLn(' directoryTitle = ',resElt.directoryTitle);
|
|
|
|
WriteLn(' hostName = ',resElt.hostName);
|
|
|
|
WriteLn(' relatedInformationPresent = ',resElt.relatedInformationPresent);
|
|
|
|
WriteLn(' snippet = ',resElt.snippet);
|
|
|
|
WriteLn(' summary = ',resElt.summary);
|
|
|
|
WriteLn(' title = ',resElt.title);
|
|
|
|
WriteLn(' URL = ',resElt.URL);
|
|
|
|
End;
|
|
|
|
Finally
|
|
|
|
qryRes.Free();
|
|
|
|
End;
|
|
|
|
Except
|
|
|
|
On E : Exception Do
|
|
|
|
WriteLn(E.Message);
|
|
|
|
End;
|
|
|
|
|
|
|
|
ReadLn();
|
|
|
|
end.
|