首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> C++ >> 關於C++

Google Search API for C/C++ 完整介紹:SOAP 介面與資料結構

     編輯:關於C++

API 特色與適用場景

  • 內建 XML 解析器、GBK/UTF-8 編解碼器 (含 GBK 編碼表)
  • 純 C 實作,標準 C 介面,易於整合至 C/C++ 專案
  • 支援 HTTP Proxy
  • 需至 Google API Console 申請 Key

核心資料結構 (節錄自標頭檔)

// 基本型別對應
typedef char* xsd__string;
typedef int xsd__int;
typedef bool xsd__boolean;
typedef double xsd__double;

// 搜尋結果項目
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__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;
};

主要 API 函式

函式用途
CreateSoapSession建立 SOAP 連線,傳入伺服器位址與 API Key
SetSoapProxy設定 HTTP Proxy (主機、埠)
doGoogleSearch執行搜尋,參數對應 Google 官方文件
doGetCachedPage取得 Google 快取頁面 (Base64 編碼)
doSpellingSuggestion拼字建議
GetSoapErrorMessage取得最後錯誤訊息
FreeSoapCache / FreeSoapSession釋放資源

Google 官方 WSDL 定義 (摘要)

WSDL 定義服務端點 https://api.google.com/search/beta2,採 RPC 風格 SOAP over HTTP,包含 doGoogleSearch、doGetCachedPage、doSpellingSuggestion 三個操作,訊息格式使用 urn:GoogleSearch 命名空間。

使用建議

  • 可在此基礎上二次封裝為 COM 元件,方便 VB/ASP/VBA 呼叫
  • 嚴禁反編譯原作者提供的 API 程式庫
  • 轉載請註明原作者 (littlestar, TRS Open Lab)
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved