免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
中文Google論壇 - PageRank, AdWords, AdSense, Froogle--使用Google的WebService[轉(zhuǎn)帖]
 使用Google的Web Service [轉(zhuǎn)帖]
http://www.daima.com.cn/Info/85/Info30450/
 
一、簡(jiǎn)介 
Google搜索引擎提供了基于SOAP的Web Service。這意味著不同的開(kāi)發(fā)語(yǔ)言、開(kāi)發(fā)環(huán)境都能夠使用這種服務(wù),另外,Google為了簡(jiǎn)化Java程序員的開(kāi)發(fā),它還提供了一套Java API接口,用于訪(fǎng)問(wèn)Web Serivce,這使得開(kāi)發(fā)一套支持Google搜索功能的程序變得十分容易。開(kāi)發(fā)人員可以將Google的搜索功能嵌入到他們的應(yīng)用程序當(dāng)中。本文將介紹如何使用這些Java API,以及如何使用google的Web Service。 
目前,Google的API還是處于Beta測(cè)試階段,因此,在A(yíng)PI的使用上還有一些限制。例如,使用這些API需要申請(qǐng)一個(gè)賬號(hào)。對(duì)于免費(fèi)申請(qǐng)的賬號(hào),為了防止開(kāi)發(fā)人員不正當(dāng)?shù)氖褂?,限制每個(gè)賬號(hào)、每天最多只能查詢(xún)1000次。目前,Google還沒(méi)有提出正式的運(yùn)營(yíng)模式和收費(fèi)方式。 
Google API目前主要提供三種服務(wù),分別如下: 
1)搜索服務(wù)。用戶(hù)提交一個(gè)搜索內(nèi)容請(qǐng)求,Google服務(wù)器將查找超過(guò)20億的網(wǎng)頁(yè)內(nèi)容,并且將滿(mǎn)足用戶(hù)需求的目標(biāo)返回給用戶(hù),一般來(lái)說(shuō)這種處理只需要幾秒的時(shí)間。 
2)緩存服務(wù)(Cache)。用戶(hù)提交一個(gè)URL,Google服務(wù)器將返回搜索器訪(fǎng)問(wèn)該URL的最新記錄。這樣,用戶(hù)很容易復(fù)用Google的搜索成果。 
3)拼寫(xiě)檢查。該功能用于檢查用戶(hù)的查詢(xún)請(qǐng)求是否有效。用戶(hù)提交一個(gè)檢查內(nèi)容,Google服務(wù)器將返回有效的、最接近該內(nèi)容的查詢(xún)請(qǐng)求,返回的查詢(xún)請(qǐng)求將符合Google的查詢(xún)規(guī)則。 

 

二、相關(guān)準(zhǔn)備工作 
為了開(kāi)發(fā)基于Java的程序,我們需要作如下準(zhǔn)備工作。 
1)建立Java開(kāi)發(fā)環(huán)境,Java SDK 1.3.1 或更新的版本。相關(guān)地址http:.//java.sun.com/J2SE 
2)下載Google API的Jar文件,Googleapi.jar。開(kāi)發(fā)人員可以到http://www.google.com/apis下載。 
3)申請(qǐng)Google訪(fǎng)問(wèn)賬號(hào),目前Google支持免費(fèi)申請(qǐng)的方式,用戶(hù)需要使用一個(gè)email賬號(hào)來(lái)獲取新賬號(hào)。注意,目前免費(fèi)賬號(hào)支持每天1000條的最大查詢(xún)量。申請(qǐng)地址:http://www.google.com/apis。 
4)(可選) 如果用戶(hù)需要通過(guò)Java程序直接發(fā)送SOAP請(qǐng)求,開(kāi)發(fā)人員需要下載相關(guān)的Java 軟件包,JAXM。下載地址:http://java.sun.com/xml 

三、SOAP的使用 
Google提供了基于SOAP的Web Service,因此用戶(hù)可以向Google服務(wù)器提交SOAP的查詢(xún)請(qǐng)求,而后Google服務(wù)器將處理這些請(qǐng)求,并返回SOAP格式的查詢(xún)結(jié)果。以下就是一個(gè)查詢(xún)請(qǐng)求和查詢(xún)結(jié)果。 
查詢(xún):例如,有一個(gè)查詢(xún)請(qǐng)求,請(qǐng)求類(lèi)型為搜索,查詢(xún)的內(nèi)容為“world cup”,賬號(hào)為“123456789”,如下為該查詢(xún)的一個(gè)例子。 
<?xml version=‘‘1.0‘‘ encoding=‘‘UTF-8‘‘?> 
<SOAP-ENV:Envelope 
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" 
xmlns:xsd="‘ target=_blank>http://www.w3.org/1999/XMLSchema"> 
<SOAP-ENV:Body> 
<ns1: doGoogleSearch xmlns:ns1="urn:GoogleSearch" 
SOAP-ENV:encodingStyle= 
"‘ target=_blank>http://schemas.xmlsoap.org/soap/encoding/"> 
<key xsi:type="xsd:string">123456789</key> 
<q xsi:type="xsd:string">"World Cup"</q> 
<start xsi:type="xsd:int">0</start> 
<maxResults xsi:type="xsd:int">10</maxResults> 
<filter xsi:type="xsd:boolean">true</filter> 
<restrict xsi:type="xsd:string"></restrict> 
<safeSearch xsi:type="xsd:boolean">false</safeSearch> 
<lr xsi:type="xsd:string"></lr> 
<ie xsi:type="xsd:string">latin1</ie> 
<oe xsi:type="xsd:string">latin1</oe> 
</ns1: doGoogleSearch > 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 
查詢(xún)結(jié)果:如果我們執(zhí)行以上查詢(xún),可以得到如下的查詢(xún)結(jié)果。其中,查詢(xún)結(jié)果總共有約2660000記錄,使用時(shí)間為0.125012秒。Item標(biāo)記代表一條查詢(xún)結(jié)果,在第一條查詢(xún)結(jié)果中,網(wǎng)站的URL為http://www.fifaworldcup.com。本例子僅僅列舉了一條查詢(xún)結(jié)果。 

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" 
xmlns:xsd="‘ target=_blank>http://www.w3.org/1999/XMLSchema"> 
<SOAP-ENV:Body> 
<ns1:doGoogleSearchResponse 
xmlns:ns1="urn:GoogleSearch" 
SOAP-ENV:encodingStyle="‘ target=_blank>http://schemas.xmlsoap.org/soap/encoding/"> 
<return xsi:type="ns1:GoogleSearchResult"> 
<documentFiltering xsi:type="xsd:boolean">false</documentFiltering> 
<estimatedTotalResultsCount xsi:type="xsd:int"> 
2660000</estimatedTotalResultsCount> 
<directoryCategories 
xmlns:ns2="http://schemas.xmlsoap.org/soap/encoding/" 
xsi:type="ns2:Array" 
ns2:arrayType="ns1:DirectoryCategory[0]"> 
</directoryCategories> 
<searchTime xsi:type="xsd:double">0.125012</searchTime> 
<resultElements 
xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/" 
xsi:type="ns3:Array" ns3:arrayType="ns1:ResultElement[10]"> 

<item xsi:type="ns1:ResultElement"> 
<cachedSize xsi:type="xsd:string">10k</cachedSize> 
<hostName xsi:type="xsd:string"/> 
<snippet xsi:type="xsd:string"></snippet> 
<directoryCategory xsi:type="ns1:DirectoryCategory"> 
<specialEncoding xsi:type="xsd:string"/> 
</directoryCategory> 
<relatedInformationPresent xsi:type="xsd:boolean"> 
true 
</relatedInformationPresent> 
<summary xsi:type="xsd:string"> 
The official site from FIFA, made by Yahoo. Daily news updates and loads of relevant information. 
</summary> 
<URL xsi:type="xsd:string"> 
</searchQuery> 
</return> 
</ns1:doGoogleSearchResponse> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 


四、使用Google API 
Google為了提高開(kāi)發(fā)人員的開(kāi)發(fā)效率,提供了一套基于Java的API,用于直接訪(fǎng)問(wèn)Google服務(wù)器。該API包裝了Google的Web Service,使用起來(lái)比Web Service更加方便。該API 包主要包括如下幾個(gè)類(lèi): 
GoogleSearch :該類(lèi)封裝了對(duì)于Google服務(wù)器的訪(fǎng)問(wèn),支持搜索和緩存(cache)功能。 
GoogleSearchDirectoryCategory :表示Google中的一個(gè)分類(lèi)目錄 
GoogleSearchFault :該類(lèi)為Exception的一個(gè)子類(lèi),用于表示API使用的錯(cuò)誤。 
GoogleSearchResult :該類(lèi)封裝了搜索的結(jié)果。 
GoogleSearchResultElement:該類(lèi)表示搜索結(jié)果中的每一條記錄。 

如下是一個(gè)例子的源代碼,用于一個(gè)簡(jiǎn)單查詢(xún),查詢(xún)請(qǐng)求為”world Cup”,查詢(xún)的賬號(hào)為”123456789”。該例子將把查詢(xún)結(jié)果打印出來(lái)。如果用戶(hù)需要近一步解析查詢(xún)結(jié)果,可以使用GoogleSearchResult和GoogleSearchResultElement類(lèi)。 

import com.google.soap.search.*; 
import java.io.*; 

public class GoogleAPITest { 

public static void main(String[] args) { 

String clientKey="123456789"; 
String query="Word Cup"; 
// Create a Google Search object, set our authorization key 
GoogleSearch s = new GoogleSearch(); 
s.setKey(clientKey); 
try { 
s.setQueryString(query); 
GoogleSearchResult r = s.doSearch(); 
System.out.println("Google Search Results:"+t.toString()); 
} catch (GoogleSearchFault f) { 
System.out.println("The call to the Google Web APIs failed:"+f.toString()); 


五、總結(jié) 
Google搜索引擎提供了搜索、緩存和拼寫(xiě)簡(jiǎn)單功能,通過(guò)Web Service可以在不同的平臺(tái)、不同的語(yǔ)言使用,為了簡(jiǎn)化SOAP的開(kāi)發(fā),Google還提供了包裝了SOAP服務(wù)的Java API,這也大大提高了Java程序員的開(kāi)發(fā)效率。隨著搜索內(nèi)容、形式的豐富,更多的開(kāi)發(fā)人員可以將這種技術(shù)運(yùn)用在自己應(yīng)用程序中,擴(kuò)展應(yīng)用程度的功能。 

打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
通過(guò)Web Service調(diào)用Google SOAP Search API
Java開(kāi)發(fā)中經(jīng)常使用到的幾種WebService技術(shù)實(shí)現(xiàn)方案
與Java Web Service相關(guān)的若干概念(JAX-WS,JAX-RS)
淺談Java中的通信機(jī)制及與C/C++ API的集成
java面試筆試題大匯總之八-J2EE及MVC方面
WebService
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服