1 / 17

Lab #2: Web API Programming Exercises

Lab #2: Web API Programming Exercises. By J. H. Wang Dec. 19, 2011. Outline. Yahoo! Term Extraction API Bing Search API Others. Platform and compiler. (The same as networking programming in any language on any platform.). Web API programming exercises. Network programming

gordy
Download Presentation

Lab #2: Web API Programming Exercises

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 • Network programming • Sending a request packet • Parsing the response from Web server • To start programming with Web API • Document: e.g. http://tw.developer.yahoo.com/cas/ • Register an API key • Start using the API • 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/ • 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/[APIMethod] • API Method: • ws: (word segmentation) • ke: (keyword extraction) • appid=<AppID> • content=<text content> (encoded in UTF-8) • format=json (or xml)

  8. HTTP POST • E.g.: http://asia.search.yahooapis.com/cas/v1/ke?appid=<ID>&format=xml&content=<content> • POST /cas/v1/ke HTTP/1.1\r\nHost: asia.search.yahooapis.com\r\nContent-Length: <len>\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nappid=<ID>&format=xml&content=<content>

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

  10. Sample response • <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:cate" xsi:schemaLocation="urn:yahoo:cate http://search.yahooapis.com/ContentAnalysisService/V1/TermExtractionResponse.xsd"><Result>italian sculptors</Result><Result>virgin mary</Result><Result>painters</Result><Result>renaissance</Result><Result>inspiration</Result></ResultSet>

  11. Parsing JSON Output • Document: 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.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= <AppID> • Sources=Web • Query=msdn blogs

  14. HTTP GET • E.g.: http://api.bing.net/json.aspx?AppId= <AppID>&Sources=Web&Query=<query> • GET /json.aspx?AppId= <AppID>&Sources=Web&Query=<query> HTTP/1.1\r\nConnection: close\r\nHost: 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=en-us&Adult=Moderate&Options=EnableHighlighting&Web.Count=10&Web.Offset=0&Web.Options=DisableHostCollapsing+DisableQueryAlterations&JsonType=callback&JsonCallback=SearchCompleted

  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\/1910567.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.ashx", "DateTime":"2008-10-23T18:13:07Z" } ] } }}

  17. Thanks for Your Attention!

More Related