Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab #2: Web API Programming Exercises By J. H. Wang Dec. 19, 2011.

Similar presentations


Presentation on theme: "Lab #2: Web API Programming Exercises By J. H. Wang Dec. 19, 2011."— Presentation transcript:

1 Lab #2: Web API Programming Exercises By J. H. Wang Dec. 19, 2011

2 Outline Yahoo! Term Extraction API Bing Search API Others

3 Platform and compiler (The same as networking programming in any language on any platform.)

4 Web API programming exercises 1.Network programming Sending a request packet Parsing the response from Web server 2.To start programming with Web API – Document: e.g. http://tw.developer.yahoo.com/cas/http://tw.developer.yahoo.com/cas/ – Register an API key – Start using the API 3.Protocol and message format – Prepare parameters in request – Parsing responses

5 Network Programming Sending an HTTP packet Parsing the HTTP responses

6 Yahoo Term Extraction API Document: http://tw.developer.yahoo.com/cas/ http://tw.developer.yahoo.com/cas/ – Register an API key – Start using the API – Request method: HTTP POST – Response format: JSON, XML

7 Yahoo! 搜尋『斷章取義』 API http://asia.search.yahooapis.com/cas/v1/[API Method] – API Method: ws: (word segmentation) ke: (keyword extraction) – appid= – content= (encoded in UTF-8) – format=json (or xml)

8 HTTP POST E.g.: http://asia.search.yahooapis.com/cas/v1/ke?appid= &format=xml&content= POST /cas/v1/ke HTTP/1.1\r\n Host: asia.search.yahooapis.com\r\n Content-Length: \r\n Content-Type: application/x-www-form- urlencoded\r\n \r\n appid= &format=xml&content=

9 Yahoo Term Extraction Web Service http://developer.yahoo.com/search/content/V1/ter mExtraction.html http://developer.yahoo.com/search/content/V1/ter mExtraction.html Sample request: – http://search.yahooapis.com/ContentAnalysisService/V1/t ermExtraction – appid: YahooDemo – context: Italian sculptors and painters of the renaissance favored the Virgin Mary for inspiration. – query: madonna

10 Sample response – italian sculptors virgin mary painters renaissance inspiration

11 Parsing JSON Output Document: http://www.json.org/http://www.json.org/ Implementations – JSON parser in C, C++, Java, Perl, PHP, Python, … – Ex. JSON_checker, and JSON_parser in C

12 Bing Search API Document: http://msdn.microsoft.com/en- us/library/dd251056.aspxhttp://msdn.microsoft.com/en- us/library/dd251056.aspx – Search: Web, images, news, video, … – Register an API key – Start using the API – Request method: HTTP GET – Response format: JSON, XML, SOAP

13 Bing Web Search Example in Web search – Sample request: – http://api.bing.net/json.aspx – AppId= – Sources=Web – Query=msdn blogs

14 HTTP GET E.g.: http://api.bing.net/json.aspx?AppId= &Sources=Web&Query= GET /json.aspx?AppId= &Sources=Web&Query= HTTP/1.1\r\n Connection: close\r\n Host: api.bing.net\r\n \r\n

15 Request Example http://api.bing.net/json.aspx?AppId=Insert your AppId here&Query=msdn blogs&Sources=Web&Version=2.0&Market=e n- us&Adult=Moderate&Options=EnableHighligh ting&Web.Count=10&Web.Offset=0&Web.Opt ions=DisableHostCollapsing+DisableQueryAlte rations&JsonType=callback&JsonCallback=Sea rchCompleted

16 Response Example { "SearchResponse":{ "Version":"2.0", "Query":{ "SearchTerms":"msdn blogs" }, "Web":{ "Total":1490, "Offset":0, "Results":[ { "Title":"Monads", "Description":"Monad 1 2 Manifesto. Jeffrey P. Snover. Aug 8, 2002. Version 1.2. What is Monad? Monad is the next generation platform for administrative automation.", "Url":"http:\/\/blogs.msdn.com\/powershell\/attachment\/1910567.ashx ", "DisplayUrl":"http:\/\/blogs.msdn.com\/powershell\/attachment\/191056 7.ashx", "DateTime":"2008-10-29T05:27:14Z" }, …, { "Title":"Software Design Invitation Proposal Template for Imagine Cup", "Description":"SINGPAPORE SOFTWARE DESIGN INVITATIONAL SUBMISSION PROPOSAL TEMPLATE. NOTE: This section contains a template, not a fixed format. Please return soft copy only – hardcopies will not be...", "Url":"http:\/\/blogs.msdn.com\/stanley\/attachment\/1610112.ashx", "DisplayUrl":"http:\/\/blogs.msdn.com\/stanley\/attachment\/1610112.as hx", "DateTime":"2008-10-23T18:13:07Z" } ] } } }

17 Thanks for Your Attention!


Download ppt "Lab #2: Web API Programming Exercises By J. H. Wang Dec. 19, 2011."

Similar presentations


Ads by Google