2
Compile and run from the command line:
3
googleapi <key> search|cached|spell <arg>
4
where <key> is the Google API license key (see http://www.google.com/apis)
6
googleapi XXXXXXXX search gSOAP
8
Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
9
either express or implied.
11
Copyright (C) 2002, Robert A. van Engelen, Florida State University.
16
#include "googleapi.nsmap"
18
int main(int argc, char **argv)
19
{ char *key, *dir, *arg;
21
soap_init2(&soap, SOAP_IO_DEFAULT, SOAP_XML_TREE);
23
{ fprintf(stderr, "Usage: googleapi <key> search|cached|spell <arg>\n");
29
if (!strcmp(dir, "search"))
30
{ struct api__doGoogleSearchResponse r;
31
if (soap_call_api__doGoogleSearch(&soap, "http://api.google.com/search/beta2", "urn:GoogleSearchAction", key, arg, 0, 10, true_, "", false_, "", "latin1", "latin1", &r))
32
{ soap_print_fault(&soap, stderr);
37
printf("documentFiltering = %d\n", (int)r._return.documentFiltering);
38
printf("searchQuery = %s\n", r._return.searchQuery?r._return.searchQuery:"<NONE>");
39
printf("searchComments = %s\n", r._return.searchComments?r._return.searchComments:"<NONE>");
40
printf("searchTips = %s\n", r._return.searchTips);
41
printf("searchTime = %f\n", r._return.searchTime);
42
printf("estimatedTotalResultsCount = %d\n", r._return.estimatedTotalResultsCount);
43
printf("estimateIsExact = %d\n", (int)r._return.estimateIsExact);
44
printf("startIndex = %d\n", r._return.startIndex);
45
printf("endIndex = %d\n", r._return.endIndex);
46
printf("resultElements = \n");
47
for (i = 0; i < r._return.resultElements.__size; i++)
48
{ const char *s1 = r._return.resultElements.__ptr[i].summary;
49
const char *s2 = r._return.resultElements.__ptr[i].URL;
50
const char *s3 = r._return.resultElements.__ptr[i].snippet;
51
const char *s4 = r._return.resultElements.__ptr[i].title;
52
const char *s5 = r._return.resultElements.__ptr[i].cachedSize;
53
const char *s6 = r._return.resultElements.__ptr[i].directoryTitle;
54
/* skipped printing of directoryCategory field */
55
printf("[%3d]\tSummary = %s\n", i+1, s1?s1:"<NONE>");
56
printf("\ttitle = %s\n", s4?s4:"<NONE>");
57
printf("\tURL = %s\n", s2?s2:"<NONE>");
58
printf("\tsnippet = %s\n", s3?s3:"<NONE>");
59
printf("\tcachedSize = %s\n", s5?s5:"<NONE>");
60
printf("\trelatedInfo = %d\n", (int)r._return.resultElements.__ptr[i].relatedInformationPresent);
61
printf("\tdirectoryTitle = %s\n", s6?s6:"<NONE>");
63
printf("directoryCategories = \n");
64
for (i = 0; i < r._return.directoryCategories.__size; i++)
65
{ const char *s1 = r._return.directoryCategories.__ptr[i].fullViewableName;
66
const char *s2 = r._return.directoryCategories.__ptr[i].specialEncoding;
67
printf("\t%s\t%s\n", s1?s1:"<NONE>", s2?s2:"<NONE>");
71
else if (!strcmp(dir, "cached"))
72
{ struct xsd__base64Binary r;
73
if (soap_call_api__doGetCachedPage(&soap, "http://api.google.com/search/beta2", "urn:GoogleSearchAction", key, arg, &r))
74
{ soap_print_fault(&soap, stderr);
79
for (i = 0; i < r.__size; i++)
84
else if (!strcmp(dir, "spell"))
86
if (soap_call_api__doSpellingSuggestion(&soap, "http://api.google.com/search/beta2", "urn:GoogleSearchAction", key, arg, &r))
87
{ soap_print_fault(&soap, stderr);
91
printf("Suggested spelling: %s\n", r?r:"<NONE>");
94
fprintf(stderr, "Unknown directive\n");
95
soap_end(&soap); /* remove all temporary and deserialized data */