SQLData Systems, Inc.
Home | Products | Services | Documents | Support
 

The sample demonstrates how to do  Google search using SQLData SOAP Client library. It also shows how to use  XML style sheet (XSLT) to transform response messages. The style sheet at http://soapclient.com/xml/google.xsl transforms the results to HTML format.

/**
GoogleSearch : Do google search for a given text.
Parameters:
	1. szKey : Your google account key.
	2. szSearchText: The string to search for.
	3. nStart: The starting record.
**/
int GoogleSearch(TCHAR * szKey, TCHAR* szSearchText, int nStart)
{
	// initialize input parameters, see http://google.com/apis for details
	char szStart[20];
	_stprintf(szStart, _T("%d"), nStart);
	TCHAR * ppParamNames[11]={"key", "q", "start", "maxResults", "filter", "restrict", "safeSearch","lr", "ie",NULL}; "oe" };
	TCHAR * ppParamValues[11]={szKey, szSearchText,szStart, "10", "0", "0", "1", "lang_en", "", "",NULL};

	// create a soapagent in debug mode (mode=4)
	SoapAgent *pSoapAgent= MakeSoapAgent(NULL, NULL, 4, NULL);
	if(pSoapAgent==NULL)
		return -1;
	vector<string>* pOutputValues;
	HRESULT hr;
	// invoke the web service.
	if(SUCCEEDED(hr=pSoapAgent->ExecuteMethod(
		"http://api.google.com/GoogleSearch.wsdl", // WSDL file
		"doGoogleSearch", // method name to be invoked.
		ppParamNames,	// vector of input parameter names.
		ppParamValues,	// vector of input parameter values.
		&pOutputValues	// pointer to vector of output parameters
		)))
	{	// transform the results to HTML and save it as searchResult.html.
		szResponse = pSoapAgent->Transform("http://soapclient.com/xml/google.xsl", 
			_T("searchResult.html"), NULL);
		_tprintf("Transformed Reponse : \n%s\n", szResponse);
	}
	else
	{
		// obtain error string when failed.
		_tprintf("Error String %s\n", pSoapAgent->GetErrorString());
	}
	DestroySoapAgent(pSoapAgent);
	return 0;
}

VB and ASP samples are available at http://soapclient.com/googlesearch.html .

Please visit http://www.SoapClient.com for more information and sample applications.

Download | Purchase | ContactFeedback

horizontal rule

Send mail to  info2-at-sqldata-dot-com with questions or comments about this web site.
Copyright 2008-2010 SQLData Systems, Inc.
Last modified: July 10, 2010