Google API 義守大學資訊工程學系 歐陽振森

Download Report

Transcript Google API 義守大學資訊工程學系 歐陽振森

Google API
義守大學資訊工程學系
歐陽振森
[email protected]
Google 服務








Google Search
Gmail
Google Maps
Google Earth
Google News
Google Image Search
Google Book Search
Google Blog Search








Google Notebook
Google Desktop
Google Toolbar
Google 學術搜尋
Google 大學搜尋
Google Alerts
YouTube
Google Calendar








orkut
Picasa
Google Docs
Blogger
Google Talk
Google Groups
Google Reader
Google SketchUp









Google Analytics
Google Translate
Google Video
Google Trends
Google Code Search
Google Patent Search
Google AdSense
Google Adwords
Google Page Creator
API

Application Programming Interface: API是一
組作為應用程式呼叫某個功能與服務的函數。
程式設計師可依據API函數撰寫程式,讓作業
系統或某個程式啟動某個程式以執行特定的功
能。



應用程式
介面
根據API定義的方式呼叫相對應的功能
Google API (1)








Android
Google AJAX Search API
Google APP Engine
Google Calendar API
Google Chart API
Gadgets
Google Gears
Google Maps API
Google API (2)





OpenSocial
YouTube API
Google Data API
Blogger API
Google AJAX Feed API
簡介






Google搜尋服務之包裝
由JavaScript所構成的函式庫
可放在自己的網站或部落格中
服務範圍:網頁搜尋、本地搜尋、影片搜尋、
部落格搜尋、新聞搜尋、書籍搜尋、圖片搜尋
組成元件:搜尋控制器、搜尋器、搜尋結果物
件、額外的設定物件
專屬論壇:Google AJAX Search API論壇
Google AJAX Search API Key


須先申請Google AJAX Search API key
申請網址:http://code.google.com/intl/zhTW/apis/ajaxsearch/signup.html
程式範例一

範例一:HelloWorld.html
搜尋控制容器



用來裝載搜尋功能的容器
所有搜尋功能的物件必須放入這個容器才能運
作
包含兩種物件:


google.search.SearchControl
google.search.SearchForm
Google.search.SearchControl

建立物件


var searchControl = new google.search.SearchControl;
加入搜尋器


addSearcher(searcher,opt_options)
搜尋器:







google.search.WebSearch (網頁搜尋)
google.search.LocalSearch (當地搜尋)
google.search.VideoSearch (影片搜尋)
google.search.BlogSearch (部落格搜尋)
google.search.NewsSearch (新聞搜尋)
google.search.BookSearch (書籍搜尋)
google.search.ImageSearch (圖片搜尋)
Google.search.SearchControl

練習一


搜尋界面繪製


draw(element, GdrawOptions)
執行關鍵字搜尋


請將各種搜尋器加入範例一中。
execute(str)
練習二

請用自己的名字當關鍵字來搜尋。
Google.search.SearchControl

搜尋不到結果時,網頁所顯示之文字


setNoResultsString(str)
練習三

請設定當搜尋不到結果,網頁顯示”Google太遜了
啦”。
Google.search.SearchForm

建立物件


var searchForm =
new google.search.SearchForm(enableClear,element);
設定點選搜尋按鈕後所呼叫的物件與函式


setOnSubmitCallback(object,method)
範例二:2-12.html
Google.search.SearchForm

設定點選搜尋輸入欄位的清除按鈕後所呼叫的
物件與函式



設定搜尋關鍵字


setOnClearCallback(object,method)
範例三:2-13.html
execute(query)
練習四

請設定點選搜尋輸入欄位的清除按鈕後彈出一個視
窗顯示搜尋關鍵字”自己的名字”。
網頁搜尋器

建立物件


限制所要搜尋的對象



var searcher=new google.search.WebSearch();
setSiteRestriction(site,refinement,moreResults)
範例四:2-15.html
對搜尋結果進行過濾



setRestriction(type,opt_value)
type: google.search.Search.RESTRICT_SAFESEARCH
opt_value: google.search.Search.SAFESEARCH_STRICT
google.search.Search.SAFESEARCH_MODERATE
google.search.Search.SAFESEARCH_OFF
本地搜尋器

建立物件


針對特定地理區域進行搜尋



var searcher=new google.search.LocalSearch();
setCenterPoint(location)
範例五:2-17.html
是否要針對地址進行搜尋


setAddressLookupMode(mode)
mode:
google.search.LocalSearch.ADDRESS_LOOKUP_DISABLED
google.search.LocalSearch.ADDRESS_LOOKUP_ENABLED
影片搜尋器

建立物件


var searcher=new google.search.VideoSearch();
搜尋結果的排序順序


setResultOrder(orderBy)
orderBy:
google.search.Search.ORDER_BY_RELEVANCE
google.search.Search.ORDER_BY_DATE
部落格搜尋器

建立物件


限制所要搜尋的對象


var searcher=new google.search.BlogSearch();
setSiteRestriction(site)
搜尋結果的排序順序


setResultOrder(orderBy)
orderBy:
google.search.Search.ORDER_BY_RELEVANCE
google.search.Search.ORDER_BY_DATE
新聞搜尋器

建立物件


限制所要搜尋的對象


var searcher=new google.search.NewsSearch();
setSiteRestriction(site)
搜尋結果的排序順序


setResultOrder(orderBy)
orderBy:
google.search.Search.ORDER_BY_RELEVANCE
google.search.Search.ORDER_BY_DATE
書籍搜尋器

建立物件


var searcher=new google.search.BookSearch();
對搜尋結果進行過濾



setRestriction(type,opt_value)
type: google.search.Search.RESTRICT_TYPE
opt_value:
google.search.BookSearch.TYPE_FULL_VIEW_BOOKS
google.search.BookSearch.TYPE_ALL_BOOKS
圖片搜尋器

建立物件


var searcher=new google.search.ImageSearch();
對搜尋結果進行過濾


setRestriction(type,opt_value)
type: google.search.Search.RESTRICT_SAFESEARCH
google.search.ImageSearch.RESTRICT_IMAGESIZE
google.search.ImageSearch.RESTRICT_COLORIZATION
google.search.ImageSearch.RESTRICT_FILETYPE
google.search.ImageSearch.RESTRICT_IMAGETYPE
圖片搜尋器

opt_value

google.search.Search.RESTRICT_SAFESEARCH




google.search.Search.SAFESEARCH_STRICT
google.search.Search.SAFESEARCH_MODERATE
google.search.Search.SAFESEARCH_OFF
google.search.ImageSearch.RESTRICT_IMAGESIZE




google.search.ImageSearch.IMAGESIZE_SMALL
google.search.ImageSearch.IMAGESIZE_MDEIUM
google.search.ImageSearch.IMAGESIZE_LARGE
google.search.ImageSearch.IMAGESIZE_EXTRA_LARGE
圖片搜尋器

google.search.ImageSearch.RESTRICT_COLORIZATION




google.search.ImageSearch.RESTRICT_FILETYPE





google.search.ImageSearch.COLORIZATION_BLACK_AND_WHITE
google.search.ImageSearch.COLORIZATION_GRAYSCALE
google.search.ImageSearch.COLORIZATION_COLOR –
google.search.ImageSearch.FILETYPE_JPG
google.search.ImageSearch.FILETYPE_PNG
google.search.ImageSearch.FILETYPE_GIF
google.search.ImageSearch.FILETYPE_BMP
google.search.ImageSearch.IMAGETYPE_FACES

google.search.ImageSearch.IMAGETYPE_FACES