2003年12月16日 星期二

Google Api研究手记

Google得api现在还处在beta阶段,他的api下载了快半年了,license key也申请了半年多,一直都没有用过。先来个大致了解吧。Google Api函数也相对比较简单。我用c#开发,所以,研究报告都是基于C#的。
拿google api带的C#例程Google Web APIs Demo.sln参考来看。基本的功能非常简单,最重要的一个就是查询某个关键字在google中搜索到的条目数量。具体调用的是
SearchButton Click事件如下:

private void searchButton_Click(object sender, System.EventArgs e) { // Create a Google Search object Google.GoogleSearchService s = new Google.GoogleSearchService(); try { // Invoke the search method Google.GoogleSearchResult r = s.doGoogleSearch(keyBox.Text, searchBox.Text, 0, 1, false, "", false, "", "", ""); // Extract the estimated number of results for the search and display it int estResults = r.estimatedTotalResultsCount; searchResultLabel.Text = Convert.ToString(estResults); } catch (System.Web.Services.Protocols.SoapException ex) { MessageBox.Show(ex.Message); } }
其中Google.GoogleSearchResult r = s.doGoogleSearch(keyBox.Text, searchBox.Text, 0, 1, false, "", false, "", "", "");创建了Google.GoogleSearchService对象的实例 s. 把 s.doGoogleSearch方法的结果返回给Google.GoogleSearchResult对象实例r来用。 s.doGoogleSearch方法带了一组参数(keyBox.Text, searchBox.Text, 0, 1, false, "", false, "", "", "");分别是(key,q,start,maxResults,filter,restricts,safeSearch,lr,ie,oe),说明如下:
Name
Description
key
Provided by Google, this is required for you to access the Google service. Google uses the key for authentication and logging.
q
(See Query Terms section for details on query syntax.)
start
Zero-based index of the first desired result.
maxResults
Number of results desired per query. The maximum value per query is 10. Note: If you do a query that doesn't have many matches, the actual number of results you get may be smaller than what you request.
filter
Activates or deactivates automatic results filtering, which hides very similar results and results that all come from the same Web host. Filtering tends to improve the end user experience on Google, but for your application you may prefer to turn it off. (See Automatic Filtering section for more details.)
restricts
Restricts the search to a subset of the Google Web index, such as a country like "Ukraine" or a topic like "Linux." (See Restricts for more details.)
safeSearch
A Boolean value which enables filtering of adult content in the search results. See SafeSearch for more details.
lr
Language Restrict - Restricts the search to documents within one or more languages.
ie
Input Encoding - this parameter has been deprecated and is ignored. All requests to the APIs should be made with UTF-8 encoding. (See Input and Output Encodings section for details.)
oe
Output Encoding - this parameter has been deprecated and is ignored. All requests to the APIs should be made with UTF-8 encoding. (See Input and Output Encodings for details.)
Google现在开放的Api实在比较简单,没有太多好说的东西,具体可以参考http://www.google.com/apis/reference.html 有问题的,可以一起交流。

[technorati relative tag]

[相关内容]

由 tristones 发表于 2003年12月16日 下午12時17分

留言

您好,我现在急需google api的license key作研究,而google现在又申请不了了,能否借我一用?
万分感谢!!!!

Posted by: qdm 发表于 2004年10月21日 上午08時44分