Api web 2.0. Representational state transfer REST is not a protocol or a format its a kind of architecture A service is accessed with its URI through.

Slides:



Advertisements
Similar presentations
3rd Annual Plex/2E Worldwide Users Conference Page based on Title Slide from Slide Layout palette. Design is cacorp Title text for Title or Divider.
Advertisements

XPathAPI XPathAPI HOME : API : j/apidocs/ Lib.
Taking Input Java Md. Eftakhairul Islam
Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 24. November 2009.
Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 24. November 2009.
REST Vs. SOAP.
Web Service Testing RESTful Web Services Snejina Lazarova Dimo Mitev
REST and JSON in WCF It is possible to implement and access REST services in WCF And still doing it object oriented This is a short presentation on how.
What are Web Services? How to use them?
WEB SERVICES in LabVIEW María del Campo IFCA-CSIC, Spain October 22, 2009, Garching.
Introduction to Web Services and Web API’s Richard Holowczak Baruch College December, 2014.
Ajax. Overview of Ajax History In the 1990s, most web sites were based on complete HTML pages; each user action required that the page be re-loaded from.
AJAX Compiled from “AJAX Programming” [Sang Shin]
XMLHttpRequest Object and XML What we should learn in this lesson –What is the XHR object? –How to create the XHR objects? –XHR object properties –XHR.
More APIs: Web Services CMPT 281. Announcements Project milestone Lab: – Web services examples.
Hints for HW#8. HW#6 Architecture Result of Query GOOG Browser with web page PHP Script client Apache web server finance.yahoo.com Send query with arguments.
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
RESTful Web Development With Nodejs and Express. REST Stands for REpresentational State Transfer Has the following constraints: ◦Client-Server ◦Stateless.
Prof. James A. Landay University of Washington Spring 2008 Web Interface Design, Prototyping, and Implementation Rich Internet Applications: AJAX, Server.
JSON (JavaScript Object Notation).  A lightweight data-interchange format  A subset of the object literal notation of JavaScript (or ECMA-262).  A.
Interactive Web Application with AJAX
Ajax (Asynchronous JavaScript and XML). AJAX  Enable asynchronous communication between a web client and a server.  A client is not blocked when an.
JavaScript & jQuery the missing manual Chapter 11
Lecture 12 – AJAX SFDV3011 – Advanced Web Development Reference: 1.
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
AJAX and Java ISYS 350. AJAX Asynchronous JavaScript and XML: – Related technologies: JavaScript, Document Object Model, XML, server-side script such.
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
REST.  REST is an acronym standing for Representational State Transfer  A software architecture style for building scalable web services  Typically,
Google Data APIs Google Data APIs : Integrando suas aplicações Java com os serviços Google.
RESTful applications Norman White. REST Representational state transfer Key concepts – Client Server architecture built on transferring resources between.
Lecture 13 – XML and JSON SFDV3011 – Advanced Web Development Reference: 1.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
Instructor, Dr. Khalili Bahram Jeevan Kumar Gogineni.
XMLHttpRequest Object When Microsoft Internet Explorer 5.0 introduced a rudimentary level of XML support, an ActiveX library called MSXML was also introduced,
Ajax. –Asynchronous JavaScript and XML –Umbrella term for technologies that often: Use client-side scripting for layout and formatting Use less than full.
AJAX (also known as: XMLHTTP, Remote Scripting, XMLHttpRequest, etc.) Matt Warden.
Ajax. –Asynchronous JavaScript and XML –Umbrella term for technologies that often: Use client-side scripting for layout and formatting Use less than full.
Facebook API Kelly Orser. Client Libraries Client libraries will simplify the calls to the platform by reducing the amount of code you have to write.
Asynchronous Javascript And XML AJAX : an introduction UFCEUS-20-2 : Web Programming.
School of Computing and Information Systems CS 371 Web Application Programming AJAX.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
SYST Web Technologies SYST Web Technologies AJAX.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
AJAX Asynchronous JavaScript and XML 1. AJAX Outline What is AJAX? Benefits Real world examples How it works 2.
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
AJAX and REST. Slide 2 What is AJAX? It’s an acronym for Asynchronous JavaScript and XML Although requests need not be asynchronous It’s not really a.
AJAX AJAX Asynchronous JavaScript and XML --- MADHAVI
INNOV-2: Build a Better Web Interface Using AJAX Chris Morgan Pandora Software Systems
Web Technology (NCS-504) Prepared By Mr. Abhishek Kesharwani Assistant Professor,UCER Naini,Allahabad.
USING ANDROID WITH THE DOM. Slide 2 Lecture Summary DOM concepts SAX vs DOM parsers Parsing HTTP results The Android DOM implementation.
JavaScript, Sixth Edition Chapter 11 Updating Web Pages with Ajax.
JavaScript and Ajax Week 10 Web site:
CITA 330 Section 10 Web Remoting Techniques. Web Remoting Web Remoting is a term used to categorize the technique of using JavaScript to directly make.
NCCUCS 軟體工程概論 Lecture 5: Ajax, Mashups April 29, 2014.
JQuery, JSON, AJAX. AJAX: Async JavaScript & XML In traditional Web coding, to get information from a database or a file on the server –make an HTML form.
AJAX. Objectives Understand and apply AJAX Using AJAX in DOJO library.
USING ANDROID WITH THE INTERNET. Slide 2 Lecture Summary Getting network permissions Working with the HTTP protocol Sending HTTP requests Getting results.
JavaScript and Ajax (Ajax Tutorial)
Unit 4 Representing Web Data: XML
Brice Copy, Mirjam Labrenz
AJAX AJAX = Asynchronous JavaScript and XML.
CS 371 Web Application Programming
AJAX and REST.
XMLHttp Object.
Ajax Design Patterns – Programming Practices in Web Services
Chapter 7 Representing Web Data: XML
Giuseppe Attardi Università di Pisa
JavaScript & AJAX.
AJAX CS-422 Dick Steflik.
Presentation transcript:

Api web 2.0

Representational state transfer REST is not a protocol or a format its a kind of architecture A service is accessed with its URI through HTTP operation like GET, POST, PUT or DELETE. Enough for most of web services Example : 3 ;)

HTTP Query with JAVA Init the HTTP query: URL url = new URL("my_url"); HttpURLConnection UrlConn = (HttpURLConnection) url.openConnection(); urlConn.setRequestMethod("GET"); urlConn.setAllowUserInteraction(false); urlConn.setDoOut put(true); Read the answer InputStream response = urlConn.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(response)); while ((String line = o_oBufReader.readLine()) != null){ //do whatever you want } Diconnect urlConn.disconnect();

AJAX Asynchronous javascript HTTP query in javascript without reloading all the page Richer interfaces Example: mail notification and instant messaging in gmail.

AJAX : init the query Var xhr; if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); // Firefox, Safari,... } else if (window.ActiveXObject) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer } or try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); //try Internet Explorer }catch(e) { xhr = new XMLHttpRequest() //firefox, safari... }

AJAX : send and process query Process function : request.onreadystatechange = function(){ // instructions }; Send the query : xhr.open('GET', ' true); xhr.send(null); Important: Same Origin Policy So use a servlet as intermediary

JSON: JavaScript Object Notation JSON object: var person = { "name" : "John" "phone" : [ {"type" : "home", "num" : "1234"}, {"type" : "mobile", "num" : "5678"} ] }; person.name; person.phone[0].num; Eval function: var JSONString = "someVar = { 'color' : 'blue' }"; eval(JSONString); Tutorial:

API flickr API_Key and secret: Note : il faut un compte Yahoo pour y accèder. URL API: d=method_name&param1=value1&param2=value2... Paramètre souvent requis: api_key –On demande la clé en ligne, cf URL ci-dessus. Recherche de photos par tags: flickr.photos.search&tags=a_tag&api_key=yo ur_key

Example of XML Response URL API: d_name&param1=value1&param2=value2... Paramètre souvent requis: api_key Recherche de photos par tags: flickr.photos.search&tags=a_tag&api_key=yo ur_key

Don't worry: API JAVA ;) Dom API: DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance(); DocumentBuilder constructeur = fabrique.newDocumentBuilder(); Document document = constructeur.parse(rdfFile); Element racine = document.getDocumentElement(); NodeList photos = racine.getElementsByTagName("photo"); for(int i = 0; i < photos.getLength(); i++){ photos.item(i).getAttributes() … } Or just forget to manipulate XML:

FlickrJ: API JAVA Init service: Flickr flickr = new Flickr(apiKey, secret, new REST()); Different interfaces: –flickr.getPhotosInterface() –flickr.getPeopleInterface() –flickr.getContactsInterface() –flickr.getLicensesInterface() –flickr.getTagsInterface() –…

FlickrJ: example Init service: Flickr flickr = new Flickr(" b3aabee4aca6a5853eca74b6", "ab7f2d30639a9828", new REST()); PhotosInterface pi = flickr.getPhotosInterface(); SearchParameters sp = new SearchParameters(); String []tabTag = {« cars »}; sp.setTags(tabTag); PhotoList photoList = pi.search(sp, 50, 1); Iterator it = photoList.iterator(); while (it.hasNext()) { Photo photo = (Photo) it.next(); out.println(" "); }

JSON and flickr format=json URL API: Example: flickr.blogs.getListflickr.blogs.getList –XML response –JSON response rsp = { "stat": "ok", "blogs": { "blog": [{ "id" : "73", "name" : "Bloxus", "url" : "..." } { "id" : "74", "name" : "Manila", "url" : "..." } ] } } URL API: Example for (var i=0; i<rsp.blogs.blog.length; i++){ var blog = rsp.blogs.blog[i]... }

Youtube API key and secret: REST interface: To request a response in JSON format, use the alt=json parameter. Server side API: Java,.NET, PHP, python … Widget and players API (client side): javascript, flash

API JAVA Youtube Import import com.google.gdata.client.youtube.YouTubeService; import com.google.gdata.util.ServiceException; Init service YouTubeService myService = new YouTubeService("the name of my app"); Init search query: YouTubeQuery query = new YouTubeQuery(new URL(URL_VIDEOS_FEED)); Appel au service: VideoFeed videoFeed = service.query(query, VideoFeed.class); for (VideoEntry ve : videoFeed.getEntries()) {... }

API Youtube Parametrize query: –search terms: query.setVideoQuery(searchTerms); –Order: RELEVANCE, VIEW_COUNT, PUBLISHED, RATING : query.setOrderBy(YouTubeQuery.OrderBy.RELEVANCE); –Number of results: query.setMaxResults(count); –Pagination: query.setStartIndex(start); –include restricted content (excluded by default): query.setIncludeRacy(true); Code example

Google search: AJAX API Basis: // create a search control var searchControl = new google.search.SearchControl(null); // add in a full set of searchers searchControl.addSearcher(new google.search.LocalSearch()); searchControl.addSearcher(new google.search.WebSearch()); searchControl.addSearcher(new google.search.VideoSearch()); searchControl.addSearcher(new google.search.BlogSearch()); searchControl.addSearcher(new google.search.NewsSearch()); searchControl.addSearcher(new google.search.ImageSearch()); searchControl.addSearcher(new google.search.BookSearch()); searchControl.addSearcher(new google.search.PatentSearch()); // tell the searcher to draw itself and tell it where to attach // Note that an element must exist within the HTML document with id "search_control" searchControl.draw(document.getElementById("search_control"));

Google search: AJAX API SearcherControl Draw Modes: –create a drawOptions object var drawOptions = new google.search.DrawOptions(); –tell the searcher to draw itself in linear mode drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_LINEAR); –tell the searcher to draw itself in linear mode drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED); –decouple the "search form" from the set of search results drawOptions.setSearchFormRoot(document.getElementById("id_dom_elem")); –Display results : searchControl.draw(element, drawOptions);

Google search: AJAX API Keeping a Search Result : // establish a keep callback searchControl.setOnKeepCallback(this, MyKeepHandler); function MyKeepHandler(result) { // clone the result html node var node = result.html.cloneNode(true); // attach it var savedResults = document.getElementById("saved_results"); savedResults.appendChild(node); }

Google map arch/ arch/

API Facebook Install facebook "Developper" application to get API_Key and secret. Interface restful: &method=METHOD_NAME&sig=METHOD_OPTIONS FacebookML: A meta language to develop facebook apps (interpreted on facebook servers) FQL: Facebook Query Language Server API: Php, java,.NET, etc;

API java pour Facebook Plus maintenue par facebook: Alternatives: Authentification de l'application: Facebook fb = new Facebook(request, response, FB_API_KEY, FB_SECRET_KEY); fb.requireLogin("") if(!face.isLogin()) return null; //can't access application FacebookRestClient fbrclient = fb.getFacebookRestClient(); Id utilisateur: fbrclient.users_getLoggedInUser();

API java pour Facebook Récupérer le nom et status de l'utilisateur courant (un peu compliqué, mais bon…): //fill the list of users ArrayList user = new ArrayList (); //set of information required on users EnumSet fields = EnumSet.of(com.facebook.api.ProfileField.NAME, com.facebook.api.ProfileField.STATUS); users.add(fbrclient.users_getLoggedInUser()); Document d = fbrclient.users_getInfo(users, fields); String userName = d.getElementsByTagName( com.facebook.api.ProfileField.NAME.fi eldName ).item(0).getTextContent(); String userName = d.getElementsByTagName( com.facebook.api.ProfileField.NAME.fi eldName ).item(0).getTextContent();

API java pour Facebook Informations sur les amis: Document d = fbrclient.friends_get(); NodeList userIDNodes = d.getElementsByTagName("uid"); Collection friends = new ArrayList (); for (int i = 0; i < userIDNodes.getLength(); i++) { Node node = userIDNodes.item(i); Integer id = Integer.valueOf(node.getTextContent()); friends.add(id); } Document infos = fbrclient.users_getInfo(users, fields); //then we can iterate on the list of friends id and get the information for(Integer id : friends){ String fieldName = infos.getElementsByTagName(...).item(i).getTextContent(); //etc. }

And more… All google apps: –Open social –Maps: –Etc. Delicious: Digg: Technorati: And most of web 2.0 platforms propose access to their data through APIs!!!

It's your turn now !!! Build a search engine that search on different web 2.0 services and propose differents médias: Photos with flickr Video with youtube People and social features with facebook And whatever you want with web 2.0 APIs.