1 / 23

Announcements

Announcements. Homecoming Engineering Tailgate Extravaganza Students need to register by October 21 st Actual game is October 29 th $10 Lunch, $15 for Lunch + Ticket 300 tickets available Now selling t-shirts and dues $10.00 Dues = Free T-Shirt!. Announcements. Speakers Dr. Gary Leavens

lani
Download Presentation

Announcements

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. Announcements • Homecoming Engineering Tailgate Extravaganza • Students need to register by October 21st • Actual game is October 29th • $10 Lunch, $15 for Lunch + Ticket • 300 tickets available • Now selling t-shirts and dues • $10.00 Dues = Free T-Shirt!

  2. Announcements • Speakers • Dr. Gary Leavens • Next week! • Florida Interactive Entertainment Academy • October 20th • Then social!

  3. APIs and You! Shane Chism, 2011

  4. What’s an API? • Application Programming Interface • Serves as an interface between different software programs and facilitates their interaction • (I want your data) + (You don’t trust me) = API • Implements multiple concepts • Object based requests • JSON / XML • Authentication Shane Chism, 2011

  5. How is a request made?

  6. How is a request made? • Multiple methods of making an API request • A request can simply be defined: • Client communicates a request to a Server • For our purposes, we’ll focus on URL based requests Example: GET https://graph.facebook.com/{userId}  Shane Chism, 2011

  7. Object Based Requests • APIs can be simple or powerful • Consider an API that only serves the time • Consider an API that translates to and from any language • Object Oriented requests make requesting complex data easy: GET https://graph.facebook.com/chism/posts • This returns all posts for user “chism” • Our main object is the user (chism). posts is our “connection,” a collection of child objects Shane Chism, 2011

  8. How do I use this data?

  9. How do I use this data? • The API server has no clue what context you’re requesting from • Web app? Desktop app? C? C#? PHP? Java? Whitespace? • It needs to send a response that can be read by any language in any context • Solution: XML!Right? …. Right? …….. Shane Chism, 2011

  10. JSON • XML is cool. • It’s traditionally been used to do what JSON is doing • Send data in a way where we can convert it into usable data structures • JSON is cooler. (opinion, but backed with facts!) • It does what XML does, but it’s much lighter weight Shane Chism, 2011

  11. JSON vs. XML

  12. JSON • Computers can read JSON fairly easily • Getting the data into the data structure, however, isn’t as fun • In PHP: • json_decode( $jsonString, true ); • Produces an associative array with proper variable types • In Java: …. Not as fun. Shane Chism, 2011

  13. JSON • Decoding JSON in Java • You can use any number of open source libraries • We’ll be using GSON • Google JSON Decoder • The trick: We need to build a container for our JSON data Shane Chism, 2011

  14. JSON • Example: Decoding JSON in Java • Suppose this is our JSON response: • Our data structure would be: { "id": "1106460174" } classmy_JSON_Container { public String id; } Shane Chism, 2011

  15. JSON • Example: Decoding JSON in Java • Suppose this is our JSON response: • Our data structure would be: { "id": "1106460174”,  "name": "Shane Chism", } classmy_JSON_Container { public String id; public String name; } Shane Chism, 2011

  16. Reading JSON { "id": "1106460174", "name": "Shane Chism", "link": "https://www.facebook.com/chism", "username": "chism", "hometown": { "id": "109466215738919", "name": "Tierra Verde, Florida" }, "languages": [ { "id": "117976438273549", "name": "SQL" }, { "id": "177492448957188", "name": "CSharp" } ] } Strings String key = value

  17. Reading JSON { "id": "1106460174", "name": "Shane Chism", "link": "https://www.facebook.com/chism", "username": "chism", "hometown": { "id": "109466215738919", "name": "Tierra Verde, Florida" }, "languages": [ { "id": "117976438273549", "name": "SQL" }, { "id": "177492448957188", "name": "CSharp" } ] } Arrays Map<String,String>

  18. Reading JSON { "id": "1106460174", "name": "Shane Chism", "link": "https://www.facebook.com/chism", "username": "chism", "hometown": { "id": "109466215738919", "name": "Tierra Verde, Florida" }, "languages": [ { "id": "117976438273549", "name": "SQL" }, { "id": "177492448957188", "name": "CSharp" } ] } Nested Arrays Collection<Map<String,String>>

  19. MAKING THE CONNECTION

  20. Making the connection • In Java we use two pre-built classes: • URL • URLConnection • More on this in the tutorial… Shane Chism, 2011

  21. OAUTH Api authentication

  22. Authentication • Often times an API will need to know that we have permission to access user data • Google, Facebook (and many others) use a protocol called OAUTH • This is extremely important, but we won’t be tackling it in this tutorial • At first blush OAuth is very complex. Pace yourself! Shane Chism, 2011

  23. APIs and You! Shane Chism, 2011

More Related