This was a fun project! With the API for Seesmic launching, I was chomping at the bit to post my videos on my blog so folks could see more videos from me. Utilizing the same architecture as some of the other WordPress plugins I’ve built, I built out a Seesmic WordPress plugin.
This plugin was different because it required me to decode JSON and work quite a bit more with multi-dimensional arrays and PHP. Sorry if that sounds like greek to you… here’s some explanation.
What’s an API?
When you type a URL into your browser’s address bar, what actually occurs is that you make a request to the server you’re trying to reach and then that server serves up the HTML and images to make the page. An API does the same thing – only the page you’re on (AJAX) or the server that your page is served from makes the request.
Instead of serving HTML and images, though, the API serves back XML, or eXtensible Markup Language or most recently, JSON. Simply put – where HTML is made to be viewed by a human, XML and JSON are designed to be consumed by a computer. It’s a strict construction of data that is returned.
APIs are useful because you can integrate your applications into others. If you build a new application out of an API, that’s typically known as a Mashup.
New technologies require new platforms
PHP5 enhanced PHP’s abilities to consume XML and JSON (SOAP-based Web Services are next!). Trying to parse XML and JSON without PHP5 on a Linux host was cumbersome and took a lot of code and resources. I would never recommend it.
I wrote this plugin using the json_decode method within PHP5.2+ since the Seesmic API’s first evolution is JSON. This function simply takes the JSON returned and throws it into an array or multi-dimensional array that can be parsed just as any array can. Arrays can be complex (it drove me nuts this afternoon), but once you understand the structure, they’re very easy to use.