This course will become read-only in the near future. Tell us at community.p2pu.org if that is a problem.

Channel Your Vision [Jan. 25, 2012, 9:02 p.m.]



This task is about getting familiar with the Twitter Application Programming Interface, or API. Load up the Twitter API docs

If you have never used an API before, never fear. You'll notice that there's a lot of information that you need to sift through!  An API call is like a way to execute a function call on someone else's computer, in this case a server hosted by a large company. Reading the API docs is basically your ticket to understanding what function calls are allowed, how you need to format them, and what information they will return. 
 
Browse through the different "resources." Click through to the full descriptions of different resource calls. You'll notice that some require authentication, which is a topic we are not covering in this challenge. But several of the available API calls do not require authentication, including search!
 
A very cool thing about restful APIs (hint) is that they make use of the same protocol that your browser uses to display web pages: HTTP. As a result, what we described as a "function call" above is just a regular old URL. The upshot is that if you construct your API call and paste it into your URL bar, it will display the results right there in your browser! What better way to take the API for a casual test run?
 
Try out the unauthenticated user_timeline API call. Start out with this basic construct for the API call:
 
 
https://api.twitter.com/1/statuses/user_timeline.json?screen_name=p2pu

 

If you click on this link you should a JSON-formatted response in your browser. (You may want to stop and marvel at how cool it is that this is literally just a bunch of plain old text that Twitter's servers just sent you, and that you can use this important plumbing to build fantastic and wonderful web applications of untold complexity). Try adding different arguments to the url, as outlined in the docs. That's not too hard, eh? 

Answer these questions as you go. 

  1. What are some of the fields returned in the user_timeline API call? What are some of the different data types (eg. string, date, integer...) 

  2. What happens when you try to submit an API call that is broken? 

  3. What specific API call will you use for your search query?

  4. There are many different types of HTTP requests: GET, POST, PUT, etc. What kind of request are you issuing? (Feel free to research this question to determine the right answer).

  5. A "path style" API call looks like example.com/api/username/search/search-term. An argument-style query uses argument strings such as example.com/api?person=username&search=search_term. How are Twitter's queries constructed? Can these formats be combined? Why might you use one versus the other in different circumstances? (Note that these questions are the subject of endless discussions amongst web developers. There is some well-known wisdom here but not necessarily a "right" answer, so treat these questions as fodder for discussion and raising new questions-- and don't spend TOO much time on it).  

  6. You will often hear people describe the Twitter (and other) APIs as "rest-ful." What makes something a "restful" API?  

Once you're done with these, you should feel comfortable formatting query parameters, submitting queries in your browser, and visually parsing long ugly blurbs of JSON text. Hooray! On to the next task.