Reverse Engineer Nike+ to create an API

May 3, 2010

Earlier in the week we cleaned out the workout room and I started running on our treadmill again. One of the things that I am excited about it the Nike+ program. It tracks runs and keeps statists online about each run. I wanted to add these stats to my blog but Nike doesn’t offer a public API. Their website was created in Flash (well actually it was created using Flex; a discussion for a later time) using ActionScript; lucky for us, ActionScript can’t access a database on its own; it needs a XML or JSON.

Finding the XML Feed

In FireFox there is a plugin called “Live HTTP headers”. This plugin will detect what information is being sent from the browser to the server. Since Flash is a client-side technology, the XML file is pulled onto the client’s machine.

Once the plugin is installed navigate to it by going to [Tools]/[Live HTTP headers]. A box will popup and if there is information in it already, hit to “Clear” button. Navigate to the Nike+ login page. As the site is loading you will notice “Live HTTP headers” adding item after item. There will be the HTML page,  SWF files, graphics (PNGs, GIFs,JPEGs), CSS and XML files.

Before you log on, hit the “Clear” button; this will make it easier to find the feed.

Log in to the site and once loaded hit “Clear” again; then in the site, click on runs.

“Live HTTP Headers” will log a ton of items, and you will have to go through them to find the XML file. Look through the document until you find a line similar to this:

http://nikerunning.nike.com/nikeplus/v2/services/app/run_list.jsp?userID=userID&startIndex=0&endIndex=1

Live HTTP Headers Box

You can also click “Save All”, and open the file with a text editor and look for the phrase “run_list.jsp”.

Open this file in a new browser and an XML file will appear with your basic information. If you get the error: “The userProfile is not public, can’t access the service”, you will go into the privacy settings and share your information.

Create a Simple XML Parser

The data I will be retrieving is “plusService/runListSummary/distance” which is the total distance run in kilometers:

<?php

$xml = simplexml_load_file(“http://nikerunning.nike.com/nikeplus/v2/services/app/run_list.jsp?userID=userID&startIndex=0&endIndex=1″);

$result = $xml->xpath(‘/plusService/runListSummary/distance’);

$kilometers = $result[0];

echo round($kilometers*.621371192) . ” miles”;

?>

Save it to a database

Since Nike+ doesn’t have an official API, I am not sure if they would appreciate you hitting their server for the XML file every time a user visits your page. Since this data doesn’t change that often (only when you upload a run, perhaps once a day) you should save this information on your server in a database and only hit it once a day.

Tags: , , ,

Leave a Reply