1 introduction to web applications & apis: tutorial presented by julian guo and jonathan jiang,...

63
1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS 510, 2014 Spring

Upload: lizbeth-shelton

Post on 17-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

1

Introduction to Web Applications & APIs: Tutorial

Presented by Julian Guo and Jonathan Jiang,Department of MIS,

The University of Arizona

Course MIS 510, 2014 Spring

Page 2: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Agenda

Architecture of Web Applications

Web Server (Tomcat)

Creating Web Application

Database

APIs

Page 3: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

3

Architecture of Web Applications

Page 4: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

4

Architecture of Web Applications Three layer architecture

Client Application Client application provides interfaces to interact with users. For web

applications, client applications are browsers.

The contents displayed on the client application are obtained from the application server.

After receiving inputs from users, the client application submits the user inputs to the application server.

Users

Page 5: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

5

Architecture of Web Applications Application Server

Application server is a container which allows server applications to run within it.

Application server handles the requests from the client application and pass them to the server application.

These requests are generally sent through HTTP (Hypertext Transfer Protocol), which specifies a set of methods and headers that allow clients and servers to interact and exchange information.

Server application then processes the requests and sends the responses back to the client application.

Server application can also access database via JDBC, if database operations are needed.

Database Many software can be used to store and manage data (e.g., MS SQL

Server, Oracle, and MySql)

Page 6: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

6

Web Server

Page 7: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

7

Web Server To build a web application, we need a server which is able to deal with

Http requests Server applications

Therefore, web server is chosen based on the programming languages by which the server application is coded.

Apache Tomcat Apache Tomcat is an open source software implementation of the Java

Servlet and JavaServer Pages (JSP) technologies.

http://tomcat.apache.org/download-70.cgi Windows Service Installer (deploy .war file), Core (on Eclipse)

Prerequisite – JDK JDK 6 or 7(latest) download: http://www.oracle.com/technetwork/java/javase/downloads/index.html

Page 8: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

8

Apache Tomcat Installation

Setup the connection port, user name and password

Installation complete

Page 9: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

9

Apache Tomcat Test

http://127.0.0.1:8080

Page 10: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

10

Apache Tomcat File Structure

TomcatRoot C:\Program Files\Apache Software Foundation\Tomcat 7.0 (default path)

TomcatRoot/bin Executable files

Tomcat7.exe – command line mode; Tomcat7w.exe – service mode

TomcatRoot/conf - Configuration files of Tomcat

TomcatRoot/lib Libraries/APIs required to run Tomcat

TomcatRoot/logs - Log files

TomcatRoot/webapps (http://localhost:8080/) Application root – Put your web applications under this folder

TomcatRoot/work Used to store compiled JSP files (cache).

Page 11: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

11

Web Application

Using JSP on Eclipse as an example

Page 12: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Create A Web Application Project Install Tomcat

Eclipse -> File -> New-> Server

Create A Web Application Eclipse -> File -> New ->

Dynamic Web Project

Put in the project name (ex. WebApp1) -> Next http://localhost:8080/WebApp1/

Page 13: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

13

Create A Web Application Project src

The source code folder

build\classes The folder for compiled

class files

Click Next

Page 14: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

14

Create A Web Application Project

Tick on ‘Generate wb.xml’ and click Finish.

Page 15: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

15

Web Application Project – File Structure Deployment Description

Summarizes current status and setting of the project

Java Resource: Src: the folder for java source codes (such as .java files) Libraries: the folder for java libraries (such as .jar files)

JavaScript Resources Built-in JavaScript libraries

Build The folder of compiled class files (*.class) and imported APIs

WebContent (Root Folder of the application) Try to create an index.jsp under this folder. All application contents should be put under this folder. WEB-INF (the system folder of a web application) contains

Configuration files (WEB-INF/web.xml) Compiled java codes (WEB-INF/classes) Third-party libraries/APIs (WEB-INF/lib)

Page 16: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

16

Deploy A Web Application Project

To deploy a web application, we first package the web application into a WAR file.

Deploy

Right-click on the project -> Export

Choose “WAR file” -> click next

Page 17: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

17

Specify the output location and click Finish.

Deploy Copy the “WAR file” to the AppRoot of the TomCat Server

C:\Program Files\Apache Software Foundation\Tomcat 7.0 \webapps Restart Tomcat

Now you can visit your web app via web browser: http://localhost:8080/WebApp1/ (From your local machine) http://yourIPAddress:8080/WebApp1/ (From other machines)

Deploy A Web Application Project

Page 18: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

18

Database

Page 19: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

19

Database A database is an organized collection of

data.

There are many different strategies for organizing data to facilitate easy access and manipulation.

A database management system (DBMS) provides mechanisms for storing, organizing, retrieving and modifying data for many users.

Page 20: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

20

JDBC (Java Database Connectivity)

Java programs communicate with databases and manipulate their data using the JDBC API.

A JDBC driver enables Java applications to connect to a database in a particular DBMS and allows you to manipulate that database using the JDBC API.

Using the JDBC API enables developers to change the underlying DBMS without modifying the Java code that accesses the database.

Most popular database management systems now provide JDBC drivers. There are also many third-party JDBC drivers available.

Page 21: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

21

Page 22: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

22

JDBC API

Java APIs Java APIs are jar files which can be unzipped by

compression software. Java API jar files contain compiled java codes (.class)

organized by following their packaged names. Some Java APIs also contain source codes.

jTDS (http://jtds.sourceforge.net/) jTDS is an open source 100% pure Java (type 4) JDBC 3.0

driver for Microsoft SQL Server (6.5, 7, 2000, 2005 and 2008, and 2012) and Sybase (10, 11, 12, and 15).

Download: http://sourceforge.net/projects/jtds/files/latest/download?source=fil

es Connection String

jdbc:jtds:<server_type>://<server>[:<port>][/<database>][;<property>=<value>[;...]]

Page 23: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

23

Import APIs Into A Web Application

To use third-party APIs, we have to import these APIs into our project.

1. Put third-party APIs under the lib folder Copy your API (jar) files into the folder WEB-INF/lib If “Referenced Libraries” contains APIs just copied, we

are all set. Otherwise, go to step 2.

2. Import APIs into your project Right click on the project -> “properties” In the properties window, choose “Java Build Path” ->

“Libraries” tab Click “Add JARs” -> select the APIs you want to import

in the pop-up window -> Click “OK” Now, we can see the selected APIs displayed in the

properties window. Click “OK” on the properties window.

“Referenced Libraries” should contains APIs imported.

Page 24: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

24

Step 2: import APIs into project

Page 25: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

25

Step 3

Page 26: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

26

Sample Code

Showing how to connect to a database, retrieve data based on a given SQL, and display the results on a JSP.

To try the demo: Import the MIS510Demo project into Eclipse

File->Import->Existing Projects into Workspace, then select the root directory of sample code.

Right Click the project->Debug As->Debug on Server

Page 27: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

27

Command Types

boolean execute()Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement.

ResultSet executeQuery()Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query.

int executeUpdate()Executes the SQL statement in this PreparedStatement object, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL statement.

Page 28: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

28

Web API

Page 29: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Web APIs Application Programming Interface (API)

a particular set of rules and specifications that a software program can follow to access and make use of the services and resources provided by another particular software program that implements that API.

serves as an interface between different software programs and facilitates their interaction

Web API typically a defined set of HTTP request messages

expressed in SOAP or REST along with a definition of the structure of response messages, typically expressed in JSON or XML.

29

Page 30: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

SOAP Simple Object Access Protocol (SOAP)

SOAP Introduction: http://msdn.microsoft.com/en-us/library/ms995800.aspx

A SOAP message is an ordinary XML document containing the following elements: An Envelope element that identifies the XML document as

a SOAP message A Header element that contains header information

contains application-specific information about the SOAP message

optional must be the first child element of the Envelope element

A Body element that contains call and response information

A Fault element containing errors and status information 30

Page 31: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

REST Representational State Transfer (REST)

Use HTTP method to invoke remote services (not XML)

The response of remote service can be in XML/JSON or any textual format

Benefits: Easy to develop Easy to debug (with standard browser) Leverage existing web application infrastructure

We will focus on REST services programming for the rest of the slides.

31

Page 32: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Server Responses Really Simple Syndication (RSS, Atom)

XML-based standard Designed for news-oriented websites to “Push”

content to readers Excellent to monitor new content from websites

XML or JavaScript Object Notation (JSON) Lightweight data-interchange format Human readable and writable and also machine

friendly Wide support from most languages (Java, C, C#,

PHP, Ruby, Python…)

32

Page 33: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

XML Processing

A variety of APIs for accessing XML have been developed and used, and some have been standardized. Existing APIs for XML processing tend to fall into these categories: Stream-oriented APIs accessible from a programming

language E.g., Simple API for XML (SAX)

Tree-traversal APIs accessible from a programming language. E.g., Document Object Model (DOM)

XML data binding, which provides an automated translation between an XML document and programming-language objects E.g., Java Architecture for XML Binding (JAXB)

Declarative transformation languages E.g., XSLT, XPath and XQuery. XPath Tutorial: http://www.w3schools.com/xpath/default.asp

33

Page 34: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

DOM

Pros of DOM: Easy to manipulate the document Can traverse the document back and forth Good for small XML files

Cons of DOM: Consumes lots of memory

JDK provides two packages related to DOM: org.w3c.dom javax.xml.parsers

Some popular JAVA xml parsers: Xerces JDOM DOM4j

34

Page 35: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

JSON

Find JSON parsers: http://www.json.org/

Page 36: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Web APIs

In MIS510 project, you will use Web APIs in your applications

I will introduce you how to use:

Facebook Social Plug-ins YouTube Video Player Photo Search from Flickr Product Reviews from Amazon Product Offers from eBay

……

36

Page 37: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Facebook Social Plug-in

http://developers.facebook.com/docs/

37

Page 38: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Example of Like Button (Click “Get Code”)

38You will see this:

Page 39: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

YouTube APIs and Tools

https://developers.google.com/youtube/

39

Page 40: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Player APIs and Data API

Start with the embedded player if you want to add a player to your website to show individual videos or a playlist.

If you're comfortable with JavaScript or Flash, you may want to use the Player APIs to customize a chromeless player.

If you are programming a device or server-side logic for a website, look at the Data API. The table below attempts to describe the experience level of a developer for each option:

40

https://developers.google.com/youtube/getting_started

Page 41: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Embedded Player

The embedded player is the simplest way to place a YouTube video on a webpage.

Once the embedded player has been added to a webpage, it can be controlled using JavaScript.

HTML Code Generation (insert this to your webpage) https://developers.google.com/youtube/youtube_player_demo

41

<object width="193" height="159"> <param name="movie" value="http://www.youtube.com/v/CL8GjenvyKM?version=3?f=videos&amp; app=youtube_gdata"></param> <param name="allowScriptAccess" value="always"></param> <embed src="http://www.youtube.com/v/CL8GjenvyKM?version=3f=videos&amp; app=youtube_gdata" type="application/x-shockwave-flash" allowscriptaccess="always" width="425" height="355"></embed></object></a><br/>

Page 42: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

YouTube Data API V2 (old)

Advanced functions of the data API requires its java client library http://code.google.com/apis/youtube/2.0/developers_guide_java.ht

ml#Getting_Started

You will need to apply for a developer key and client id to execute authenticated functions. http://code.google.com/apis/youtube/2.0/developers_guide_java.ht

ml#Authentication

Two important class (exactly playlist and video in v3): VideoFeed: represent lists of videos, such as standard feeds,

uploads, subscriptions, and favorite videos VideoEntry: Each video entry corresponds to exactly one

YouTube video and contains information about that video.

42

Page 43: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

YouTube Video Search Example: V2

Description of the YouTube video search function http://code.google.com/intl/en/apis/youtube/2.0/developers_guide_java.htm

l#Searching_for_Videos Query parameter definition

http://code.google.com/intl/en/apis/youtube/2.0/reference.html#Query_parameter_definitions

A search query example for videos that match the search term “puppy”. http://gdata.youtube.com/feeds/api/videos?

q=puppy&orderby=viewCount The query can be generated using the following Java code:

YouTubeQuery query = new YouTubeQuery(new

URL("http://gdata.youtube.com/feeds/api/videos")); query.setOrderBy(YouTubeQuery.OrderBy.VIEW_COUNT); query.setFullTextQuery("puppy"); //print resultVideoFeed videoFeed = service.query(query, VideoFeed.class); printVideoFeed (videoFeed, true);

43

Page 44: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

YouTube Data API V3

With Data API, it is possible to search for videos, retrieve standard feeds, and see related content. A program can also authenticate as a user to upload videos, modify user playlists, and more.

https://developers.google.com/youtube/v3/ Register your application with Google Response in JSON 2 important recourse types: playlist, video 4 operations: list, insert, update, and delete

44

Page 45: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Flickr API

Flickr API Main Page: http://www.flickr.com/services/api/

API Key Application http://www.flickr.com/services/api/keys/

Request Format Rest, XML_RPC, SOAP

Response Format Rest, XML_RPC, SOAP, JSON, PHP

45

Page 46: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Photo Search

Flickr Photo Search Method Description:

http://www.flickr.com/services/api/flickr.photos.search.html Explorer:

http://www.flickr.com/services/api/explore/?method=flickr.photos.search

Steps: Apply for a Flickr API Key Send a search request to Flickr Server in your preferred format Receive the response in your preferred format Parse the result and get the photo URLs

To construct photo URLs: http://www.flickr.com/services/api/misc.urls.html

46

Page 47: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Photo Search Example – REST format

Request Format: http://api.flickr.com/services/rest/?

method=flickr.photos.search&api_key=yourkey&argument=value

Example: Request (to search photos that have “tucson” in its description):

http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=e7c88ea43041aff2df564188d4609849&text=tucson

Response:

Extracted Image URL and Web Page URL: http://farm6.staticflickr.com/5288/5368668124_d216292c15.jpg http://farm6.staticflickr.com/8109/8568179136_daa8f790f7.jpg http://www.flickr.com/photos/48553200@N04/5368668124 47

Page 48: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Amazon APIs

Amazon Web Services (AWS) http://aws.amazon.com/

Amazon SDK for Java http://aws.amazon.com/sdkforjava/

We introduce Amazon Product Advertising API Access Amazon Product Selection

gives you access to Amazon’s collection of millions of products in categories such as books, music …

Leverage Amazon Product Discovery capabilities lets you leverage Amazon’s customer-centric features

such as Product Search, Customer Reviews, Similar Products...

Monetize your website

48

Page 49: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

49

Product Advertising API

General Info Main page of Amazon Product Advertising API

https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html

Documentation for Product Advertising API http://docs.aws.amazon.com/

AWSECommerceService/latest/DG/RG_Offers.html

Sign up for Product Advertising API https://affiliate-program.amazon.com/gp/flex/

advertising/api/sign-in.html

Java Developer Center https://aws.amazon.com/java/

Page 50: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

REST Format

http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&Operation=ItemSearch& AWSAccessKeyId=[Access Key ID]&AssociateTag=[ID]&SearchIndex=Apparel& Keywords=Shirt&Timestamp=[YYYY-MM-DDThh:mm:ssZ]&Signature=[Request Signature]

50

Page 51: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Search for sample code

Make programming easier by learning from sample code http://aws.amazon.com/code/Product-Advertising-API We use Java Programming and REST: Product Advertising API Signed Requests Sample Code -

Java REST/QUERY This API requires a program to deal with signature Learn from Java Sample Code (Page 58-60):

http://awsdocs.s3.amazonaws.com/Associates/latest/prod-adv-api-dg.pdf

You can deploy sample code on your machine and run it

51

Page 52: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

From sample code

We know that we need other things: The “AWS Access Key ID,” for private String awsAccessKeyId = "AKIAJBYONHJZOPJ2B2CA"; The “AWS Secret Key,” for private String awsSecretKey =

"f2qzaLqNEGD5A5KPL7lPgiDCMJQQYid9OkEpIGUe"; Download and import an external JAR:

http://commons.apache.org/proper/commons-codec/ because we use “import

org.apache.commons.codec.binary.Base64;” Search for these things and fix them. Also, you can refer to

documentation.

52

Page 53: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Sign up Amazon Associate Account

53

Login using your Amazon Associate Account.

Page 54: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Product Advertising API

54

AssociateTag

Page 55: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Go to IAM (AWS Identity and Access Management) Console

55

More information: http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html

IAM Console: https://console.aws.amazon.com/iam/home?#home

Page 56: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Get Access Key and Secret Access Key

You can get an Access key ID and an secret access key by creating a user. Finally you will get them:

56

Page 57: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Try “ItemLookUp” operation

57

……Map<String, String> params = new HashMap<String, String>(); params.put("Service", "AWSECommerceService"); params.put("Version", "2010-10-01"); params.put("Operation", "ItemLookup"); params.put("ItemId", ITEM_ID); params.put("ResponseGroup", "EditorialReview"); params.put("AssociateTag", "i0484-20"); requestUrl = helper.sign(params); System.out.println("Signed Request is \"" + requestUrl + "\"");……

Page 58: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Generate a URL for Requesting REST resource

Type this URL on your browser, then you will get a XML file.

Parse this XML file using Java DOM (Using URL string as input of DOM).

Use fetched information on your website.

58

Page 59: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

59

Amazon Product Advertising API Summary

Steps to search Amazon Sign up Amazon Associate Apply for a API key Generate search conditions Generate a parameter string Generate a query URL Send a search request to Amazon server Receive the query result (XML format) Parse the result and display products on JSP

Have to handle namespace issue

Page 60: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

eBay API

Main page: http://developer.ebay.com/common/api/

eBay Web Services Overview https://go.developer.ebay.com/developers/ebay/

products/ Available APIs include:

Finding API, Best Match API (not available now), Merchandising API, Shopping API, Feedback API, Trading API, Client Alerts API , Platform Notifications API, Research API for eBay, etc.

Which API to use with your application? https://go.developer.ebay.com/developers/ebay/

documentation-tools/api-products-feature

60

Page 61: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

eBay Finding API

eBay Finding API: to search for eBay items: https://go.developer.ebay.com/developers/ebay/products/finding-api Search for items based on a keyword query Search for items associated with a specific product Browse for items in a specific category or in an eBay store Filter search results by item listing details, such as price, condition,

etc. Refine searches by the characteristics of an item (i.e., aspects), such

as brand, style, etc. Retrieve category and aspect metadata Get keyword recommendations to improve search results

Formats: Name-Value Syntax, XML, SOAP, JSON Protocols: HTTP GET and POST Need to apply for a API key

61

Page 62: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

Example of method findItemsByKeywords

http://svcs.ebay.com/services/search/FindingService/v1?   OPERATION-NAME=findItemsByKeywords&   SERVICE-VERSION=1.0.0&   SECURITY-APPNAME=YourAppID&   RESPONSE-DATA-FORMAT=XML&   REST-PAYLOAD&   keywords=harry%20potter%20phoenix&   itemFilter(0).name=MaxPrice&   itemFilter(0).value=10.00&   itemFilter(0).paramName=Currency&   itemFilter(0).paramValue=USD&   itemFilter(1).name=FreeShippingOnly&   itemFilter(1).value=true&   paginationInput.entriesPerPage=2

The query URL has its own syntax called “name-value syntax.” In this way, eBay doesn’t provide Java program that helps generate queries.

62

Page 63: 1 Introduction to Web Applications & APIs: Tutorial Presented by Julian Guo and Jonathan Jiang, Department of MIS, The University of Arizona Course MIS

The End

Thank you!

63