• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

c#访问gooleAPI(原创)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
 
  • 准备工作

要使用googleAPI 来开发自己的桌面应用程序,先要做下面的准备工作:

1. 首先在下面地址http://www.google.com/apis/download.html下载the Google Web APIs Developer's Kit

2. 然后在下面地址https://www.google.com/accounts/NewAccount?continue=http://api.google.com/createkey&followup=http://api.google.com/createkey注册一个 license key 以使用google提供的搜索服务。

  • 新建一个Google Search应用程序

1.       新建一个Windows From 项目命名为Google Search

2.       添加Web引用,以便使用google web services。具体做法是将下载的the Google Web APIs Developer's Kit中的GoogleSearch.wsdl文件放入本地的服务器上,然后在VS中右键点击资源管理器中的引用,再选择添加Web引用,然后输入GoogleSearch.wsdl文件在本机服务器上的地址http://localhost/GoogleSearch.wsdl,更改Web引用名为GoogleSearch后,点击添加引用后返回。

3.       进行界面设计,添加3个控件,TextBox(用于输入关键字)Button(用于提交信息),RichTextBox(用于显示搜索结果信息)。如图:

4.       编写事件处理。

1)         添加命名空间。using Google_Search.googlesearch;

2)         双击Button控件,在Button的事件处理中添加下面的代码:
 
 

 1 try
 2
 3

   3)        按ctrl+F5就能测试应用程序了。

 

l       GoogleSearchServicesdoGoogleSearch方法

   

    需要进行搜索先建立一个GoogleSearchServices 类的对象,然后调用doGoogleSearch方法取得信息。下面是google提供的对该方法的描述。

public doGoogleSearch(string key, string q, int start, int maxResults, bool filter, string restrict, bool safeSearch, string lr, string ie, string oe)

下面对各个参数进行介绍:

Key:这是由google提供的一个认证用的ID,可以在http://www.google.com/apis/申请。由于目前是测试阶段,每个ID一天只提供1000次的搜索服务请求。

q:这个就是要搜索的关键字。string类型

start:结果开始的索引数,从0开始。 int 类型

maxresults:返回的结果数的最大值,最大为10int 类型

filter:用于标识是否对搜索的结果进行过滤,所进行的过滤是对于同一主机上的内容只返回1—2个结果。bool类型

restrict:用于限定搜索的国家或地区,如果为空,表示不限制。string 类型。

下表将列出所有能选的代号。

国家

代号

国家

代号

国家

代号

国家

代号

Andorra

countryAD

Estonia

countryEE

Kazakhstan

countryKZ

Qatar

countryQA

United Arab Emirates

countryAE

Egypt

countryEG

Lao People's Democratic Republic

countryLA

Reunion

countryRE

Afghanistan

countryAF

Western Sahara

countryEH

Lebanon

countryLB

Romania

countryRO

Antigua and Barbuda

countryAG

Eritrea

countryER

Saint Lucia

countryLC

Russian Federation

countryRU

Anguilla

countryAI

Spain

countryES

Liechtenstein

countryLI

Rwanda

countryRW

Albania

countryAL

Ethiopia

countryET

Sri Lanka

countryLK

Saudi Arabia

countrySA

Armenia

countryAM

European Union

countryEU

Liberia

countryLR

Solomon Islands

countrySB

Netherlands Antilles

countryAN

Finland

countryFI

Lesotho

countryLS

Seychelles

countrySC

Angola

countryAO

Fiji

countryFJ

Lithuania

countryLT

Sudan

countrySD

Antarctica

countryAQ

Falkland Islands (Malvinas)

countryFK

Luxembourg

countryLU

Sweden

countrySE

Argentina

countryAR

Micronesia, Federated States of

countryFM

Latvia

countryLV

Singapore

countrySG

American Samoa

countryAS

Faroe Islands

countryFO

Libyan Arab Jamahiriya

countryLY

St. Helena

countrySH

Austria

countryAT

France

countryFR

Morocco

countryMA

Slovenia

countrySI

Australia

countryAU

France, Metropolitan

countryFX

Monaco

countryMC

Svalbard and JanMayenIslands

countrySJ

Aruba

countryAW

Gabon

countryGA

Moldova

countryMD

Slovakia (SlovakRepublic)

countrySK

Azerbaijan

countryAZ

United Kingdom

countryUK

Madagascar

countryMG

Sierra Leone

countrySL

Bosnia and Herzegowina

countryBA

Grenada

countryGD

Marshall Islands

countryMH

San Marino

countrySM

Barbados

countryBB

Georgia

countryGE

Macedonia, The FormerYugoslavRepublic of

countryMK

Senegal

countrySN

Bangladesh

countryBD

French Quiana

countryGF

Mali

countryML

Somalia

countrySO

Belgium

countryBE

Ghana

countryGH

Myanmar

countryMM

Suriname

countrySR

Burkina Faso

countryBF

Gibraltar

countryGI

Mongolia

countryMN

Sao Tome and Principe

countryST

Bulgaria

countryBG

Greenland

countryGL

Macau

countryMO

El Salvador

countrySV

Bahrain

countryBH

Gambia

countryGM

Northern Mariana Islands

countryMP

Syria

countrySY

Burundi

countryBI

Guinea

countryGN

Martinique

countryMQ

Swaziland

countrySZ

Benin

countryBJ

Guadeloupe

countryGP

Mauritania

countryMR

Turks and Caicos Islands

countryTC

Bermuda

countryBM

Equatorial Guinea

countryGQ

Montserrat

countryMS

Chad

countryTD

Brunei Darussalam

countryBN

Greece

countryGR

Malta

countryMT

French Southern Territories

countryTF

Bolivia

countryBO

South Georgia and the South Sandwich Islands

countryGS

Mauritius

countryMU

Togo

countryTG

Brazil

countryBR

Guatemala

countryGT

Maldives

countryMV

Thailand

countryTH

Bahamas

countryBS

Guam

countryGU

Malawi

countryMW

Tajikistan

countryTJ

Bhutan

countryBT

Guinea-Bissau

countryGW

Mexico

countryMX

Tokelau

countryTK

Bouvet Island

countryBV

Guyana

countryGY

Malaysia

countryMY

Turkmenistan

countryTM

Botswana

countryBW

Hong Kong

countryHK

Mozambique

countryMZ

Tunisia

countryTN

Belarus

countryBY

Heard and Mc DonaldIslands

countryHM

Namibia

countryNA

Tonga

countryTO

Belize

countryBZ

Honduras

countryHN

New Caledonia

countryNC

East Timor

countryTP

Canada

countryCA

Croatia (local name: Hrvatska)

countryHR

Niger

countryNE

Turkey

countryTR

Cocos (Keeling) Islands

countryCC

Haiti

countryHT

Norfolk Island

countryNF

Trinidad and Tobago

countryTT

Congo, The Democratic Republic of the

countryCD

Hungary

countryHU

Nigeria

countryNG

Tuvalu

countryTV

Central African Republic

countryCF

Indonesia

countryID

Nicaragua

countryNI

Taiwan

countryTW

Congo

countryCG

Ireland

countryIE

Netherlands

countryNL

Tanzania

countryTZ

Switzerland

countryCH

Israel

countryIL

Norway

countryNO

Ukraine

countryUA

Cote D'ivoire

countryCI

India

countryIN

Nepal

countryNP

Uganda

countryUG

Cook Islands

countryCK

British Indian Ocean Territory

countryIO

Nauru

countryNR

United States Minor Outlying Islands

countryUM

Chile

countryCL

Iraq

countryIQ

Niue

countryNU

United States

countryUS

Cameroon

countryCM

Iran (Islamic Republic of)

countryIR

New Zealand

countryNZ

Uruguay

countryUY

China

countryCN

Iceland

countryIS

Oman

countryOM

Uzbekistan

countryUZ

Colombia

countryCO

Italy

countryIT

Panama

countryPA

Holy See (Vatican CityState)

countryVA

Costa Rica

countryCR

Jamaica

countryJM

Peru

countryPE

Saint Vincent and the Grenadines

countryVC

Cuba

countryCU

Jordan

countryJO

French Polynesia

countryPF

Venezuela

countryVE

Cape Verde

countryCV

Japan

countryJP

Papua New Guinea

countryPG

Virgin Islands (British)

countryVG

Christmas Island

countryCX

Kenya

countryKE

Philippines

countryPH

Virgin Islands (U.S.)

countryVI

Cyprus

countryCY

Kyrgyzstan

countryKG

Pakistan

countryPK

Vietnam

countryVN

Czech Republic

countryCZ

Cambodia

countryKH

Poland

countryPL

Vanuatu

countryVU

Germany

countryDE

Kiribati

countryKI

St. Pierre and Miquelon

countryPM

Wallis and Futuna Islands

countryWF

Djibouti

countryDJ

Comoros

countryKM

Pitcairn

countryPN

Samoa

countryWS

Denmark

countryDK

Saint Kitts and Nevis

countryKN

Puerto Rico

countryPR

Yemen

countryYE

Dominica

countryDM

Korea, Democratic People's Republic of

countryKP

Palestine

countryPS

Mayotte

countryYT

Dominican Republic

countryDO

Korea, Republic of

countryKR

Portugal

countryPT

Yugoslavia

countryYU

Algeria

countryDZ

Kuwait

countryKW

Palau

countryPW

South Africa

countryZA

Ecuador

countryEC

Cayman Islands

countryKY

Paraguay

countryPY

Zambia

countryZM

 

 

 

 

 

 

Zaire

countryZR

 

       safeSearch:使用一个bool值表示是否过滤垃圾信息。

       lr:对语言的限制,string类型可选代号如下表:

语言

代号

 

语言

代号

Arabic

lang_ar

 

Icelandic

lang_is

Chinese (S)

lang_zh-CN

 

Italian

lang_it

Chinese (T)

lang_zh-TW

 

Japanese

lang_ja

Czech

lang_cs

 

Korean

lang_ko

Danish

lang_da

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
CEFjs调用C#封装类含注释发布时间:2022-07-13
下一篇:
利用C#将SQLServer数据库迁移到Oracle数据库方法探索发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap