Display your Most Popular Posts with Clicky’s API
One of the sessions I did today was on integrating external sites to your own site via API’s. Though the talk was supposed to be non-technical, I couldn’t help but dabble in the code a little. I wanted to dispel the myth of how difficult it was to connect to an external site and pull in data via XML. One attendee was kind enough to re-enact her facial expressions of confusion to me after the presentation (I wish I had it on video!).
When you request data via an API, it’s the same exact process a web browser utilizes. The browser makes a request to the server for the appropriate page (data) and it’s returned and rendered in the browser. With an Application Programming Interface, the server makes the request and then you program how you wish that content to be rendered in the web page yourself. Pretty straight forward!
To illustrate the process, I provided a sample where I query the API of Clicky Web Analytics and get the XML in the result set. It was done with this much PHP (false id and sitekey):

The code requests the XML, parses it and then displays it in a typical HTML list.
Link to Code. Your site must be running PHP 5.2 with cURL enabled. Please don’t email me if it doesn’t work on your server (I get A LOT of emails like this). If you want to experiment with additional APIs out there, be sure to check out Programmable Web, the most comprehensive resource of APIs and Web Services on the net.
Of course, thanks to geeks like me who love to experiment with APIs, we build plugins and widgets for WordPress and other sites so that you don’t have to!





