程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> Google搜索客戶端API for C/C++

Google搜索客戶端API for C/C++

編輯:關於C++

Google 網站上提供了goole search client api for Java和for dot.net的版本,大家可以參考.

For C/C++的版本特點如下

內置XML解析器.

內置gbk/utf-8編碼/解碼器(包含GBK編碼表)

采用Pure C編寫,采用標准C接口.

支持http代理.

用戶需要在http://api.google.com/createkey申請key

演示程序中的key是一個網友給我的,僅供測試用,演示程序中的代理可能連接不上,由於沒有設置超時,可能處於等待狀態(sorry.....)

函數中各個參數的意義和http://www.google.com/apis/reference.html的說明一樣,對此不作過多的介紹.

建議在此基礎上開發二次應用,如封裝成COM,但不得對作者提供的api進行反編譯.

如需轉載,請注明原作者,謝謝合作.歡迎交流.

函數接口

/************************************************************************/
      /*google search client api for c/c++*/
      /*By littlestar,2003,TRS Open Lab*/
/************************************************************************/
//go http://www.google.com/apis/reference.html for more information
/*start primitive data types*/
#ifdef _SOAP_TYPES
typedef char * xsd__string;
typedef int xsd__int;
struct xsd__base64Binary
{
  unsigned char *__ptr;
  int __size;
};
typedef bool xsd__boolean;
typedef double xsd__double;
/*end primitive data types*/
struct DirectoryCategoryArray
{
  struct typens__DirectoryCategory * __ptr;
  int __size;
  int __offset;
};
struct typens__ResultElement
{
  xsd__string summary;
  xsd__string URL;
  xsd__string snippet;
  xsd__string title;
  xsd__string cachedSize;
  xsd__boolean relatedInformationPresent;
  xsd__string hostName;
  struct typens__DirectoryCategory * directoryCategory;
  xsd__string directoryTitle;
};
struct typens__doGoogleSearchResponse
{
  struct typens__GoogleSearchResult * _return_;
};
struct typens__DirectoryCategory
{
  xsd__string fullViewableName;
  xsd__string specialEncoding;
};
struct typens__GoogleSearchResult
{
  xsd__boolean documentFiltering;
  xsd__string searchComments;
  xsd__int estimatedTotalResultsCount;
  xsd__boolean estimateIsExact;
  struct ResultElementArray * resultElements;
  xsd__string searchQuery;
  xsd__int startIndex;
  xsd__int endIndex;
  xsd__string searchTips;
  struct DirectoryCategoryArray * directoryCategories;
  xsd__double searchTime;
};
struct ResultElementArray
{
  struct typens__ResultElement * __ptr;
  int __size;
  int __offset;
};
struct typens__doSpellingSuggestionResponse
{
  xsd__string _return_;
};
struct typens__doGetCachedPageResponse
{
  struct xsd__base64Binary * _return_;
};
#endif
//建立Soap連接
extern "C" int _stdcall CreateSoapSession(void **SoapSessionHandle,char
*strServerAdd,char *key);
//設置代理服務器,支持http代理.
extern "C" int _stdcall SetSoapProxy(void *SoapSessionHandle,char
*strProxyHost,int ProxyPort);
//頁面檢索
extern "C" int _stdcall doGoogleSearch(void *SoapSessionHandle, xsd__string
q, xsd__int start, xsd__int maxResults, xsd__boolean filter,
xsd__string restrict_, xsd__boolean safeSearch, xsd__string lr,
xsd__string ie, xsd__string oe, struct typens__doGoogleSearchResponse *
out);
//取得google服務器上的緩存頁面
extern "C" int _stdcall doGetCachedPage(void *SoapSessionHandle,
xsd__string url, struct typens__doGetCachedPageResponse * out );
//拼寫檢查
extern "C" int _stdcall doSpellingSuggestion(void *SoapSessionHandle,
xsd__string phrase, struct typens__doSpellingSuggestionResponse * out );
//取得SOAP錯誤消息
extern "C" char* _stdcall GetSoapErrorMessage(void *SoapSessionHandle);
//釋放SOAP緩存.
extern "C" int _stdcall FreeSoapCache(void *SoapSessionHandle);
//釋放Soap連接
extern "C" int _stdcall FreeSoapSession(void **SoapSessionHandle);
google 提供的wsdl文件<?xml version="1.0"?>
<!-- WSDL description of the Google Web APIs.
   The Google Web APIs are in beta release. All interfaces are subject to
   change as we refine and extend our APIs. Please see the terms of use
   for more information. -->
<!-- Revision 2002-08-16 -->
<definitions name="GoogleSearch"
       targetNamespace="urn:GoogleSearch"
       xmlns:typens="urn:GoogleSearch"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
       xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
       xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
       xmlns="http://schemas.xmlsoap.org/wsdl/">
 <!-- Types for search - result elements, directory categories -->
 <types>
  <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="urn:GoogleSearch">
      
   <xsd:complexType name="GoogleSearchResult">
    <xsd:all>
     <xsd:element name="documentFiltering"     
type="xsd:boolean"/>
     <xsd:element name="searchComments"       
type="xsd:string"/>
     <xsd:element name="estimatedTotalResultsCount" type="xsd:int"/>
     <xsd:element name="estimateIsExact"      
type="xsd:boolean"/>
     <xsd:element name="resultElements"       
type="typens:ResultElementArray"/>
     <xsd:element name="searchQuery"        
type="xsd:string"/>
     <xsd:element name="startIndex"         type="xsd:int"/>
     <xsd:element name="endIndex"          type="xsd:int"/>
     <xsd:element name="searchTips"         
type="xsd:string"/>
     <xsd:element name="directoryCategories"    
type="typens:DirectoryCategoryArray"/>
     <xsd:element name="searchTime"         
type="xsd:double"/>
    </xsd:all>
   </xsd:complexType>
   <xsd:complexType name="ResultElement">
    <xsd:all>
     <xsd:element name="summary" type="xsd:string"/>
     <xsd:element name="URL" type="xsd:string"/>
     <xsd:element name="snippet" type="xsd:string"/>
     <xsd:element name="title" type="xsd:string"/>
     <xsd:element name="cachedSize" type="xsd:string"/>
     <xsd:element name="relatedInformationPresent"
type="xsd:boolean"/>
     <xsd:element name="hostName" type="xsd:string"/>
     <xsd:element name="directoryCategory"
type="typens:DirectoryCategory"/>
     <xsd:element name="directoryTitle" type="xsd:string"/>
    </xsd:all>
   </xsd:complexType>
 
   <xsd:complexType name="ResultElementArray">
    <xsd:complexContent>
     <xsd:restriction base="soapenc:Array">
       <xsd:attribute ref="soapenc:arrayType"
wsdl:arrayType="typens:ResultElement[]"/>
     </xsd:restriction>
    </xsd:complexContent>
   </xsd:complexType>
   <xsd:complexType name="DirectoryCategoryArray">
    <xsd:complexContent>
     <xsd:restriction base="soapenc:Array">
       <xsd:attribute ref="soapenc:arrayType"
wsdl:arrayType="typens:DirectoryCategory[]"/>
     </xsd:restriction>
    </xsd:complexContent>
   </xsd:complexType>
   <xsd:complexType name="DirectoryCategory">
    <xsd:all>
     <xsd:element name="fullViewableName" type="xsd:string"/>
     <xsd:element name="specialEncoding" type="xsd:string"/>
    </xsd:all>
   </xsd:complexType>
  </xsd:schema>
 </types>
 <!-- Messages for Google Web APIs - cached page, search, spelling. -->
      
 <message name="doGetCachedPage">
  <part name="key"      type="xsd:string"/>
  <part name="url"      type="xsd:string"/>
 </message>
 <message name="doGetCachedPageResponse">
  <part name="return"     type="xsd:base64Binary"/>
 </message>
 <message name="doSpellingSuggestion">
  <part name="key"      type="xsd:string"/>
  <part name="phrase"     type="xsd:string"/>
 </message>
 <message name="doSpellingSuggestionResponse">
  <part name="return"     type="xsd:string"/>
 </message>
 <!-- note, ie and oe are ignored by server; all traffic is UTF-8. -->
 <message name="doGoogleSearch">
  <part name="key"      type="xsd:string"/>
  <part name="q"       type="xsd:string"/>
  <part name="start"     type="xsd:int"/>
  <part name="maxResults"   type="xsd:int"/>
  <part name="filter"     type="xsd:boolean"/>
  <part name="restrict"    type="xsd:string"/>
  <part name="safeSearch"   type="xsd:boolean"/>
  <part name="lr"       type="xsd:string"/>
  <part name="ie"       type="xsd:string"/>
  <part name="oe"       type="xsd:string"/>
 </message>
 <message name="doGoogleSearchResponse">
  <part name="return"     type="typens:GoogleSearchResult"/>     
 </message>
 <!-- Port for Google Web APIs, "GoogleSearch" -->
 <portType name="GoogleSearchPort">
  <operation name="doGetCachedPage">
   <input message="typens:doGetCachedPage"/>
   <output message="typens:doGetCachedPageResponse"/>
  </operation>
  <operation name="doSpellingSuggestion">
   <input message="typens:doSpellingSuggestion"/>
   <output message="typens:doSpellingSuggestionResponse"/>
  </operation>
  <operation name="doGoogleSearch">
   <input message="typens:doGoogleSearch"/>
   <output message="typens:doGoogleSearchResponse"/>
  </operation>
 </portType>
 <!-- Binding for Google Web APIs - RPC, SOAP over HTTP -->
 <binding name="GoogleSearchBinding" type="typens:GoogleSearchPort">
  <soap:binding style="rpc"
         transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="doGetCachedPage">
   <soap:operation soapAction="urn:GoogleSearchAction"/>
   <input>
    <soap:body use="encoded"
          namespace="urn:GoogleSearch"
         
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
   </input>
   <output>
    <soap:body use="encoded"
          namespace="urn:GoogleSearch"
         
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
   </output>
  </operation>
  <operation name="doSpellingSuggestion">
   <soap:operation soapAction="urn:GoogleSearchAction"/>
   <input>
    <soap:body use="encoded"
          namespace="urn:GoogleSearch"
         
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
   </input>
   <output>
    <soap:body use="encoded"
          namespace="urn:GoogleSearch"
         
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
   </output>
  </operation>
  <operation name="doGoogleSearch">
   <soap:operation soapAction="urn:GoogleSearchAction"/>
   <input>
    <soap:body use="encoded"
          namespace="urn:GoogleSearch"
         
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
   </input>
   <output>
    <soap:body use="encoded"
          namespace="urn:GoogleSearch"
         
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
   </output>
  </operation>
 </binding>
 <!-- Endpoint for Google Web APIs -->
 <service name="GoogleSearchService">
  <port name="GoogleSearchPort" binding="typens:GoogleSearchBinding">
   <soap:address location="http://api.google.com/search/beta2"/>
  </port>
 </service>
</definitions>
(全文完)

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved