Accessing Nike+ data with PHP

Avatar von Stephanie Ehrling

Nike+ is a feature for the iPod nano which allows to measure time, distance and speed of runnings with a small sensor in running shoes that sends data to a transmitter on the iPod. Those data are sent to a users Nike+ account by iTunes whenever the iPod is synchronized. On the Nike+ website there is a report of runnings, the average speed, total kilometers run etc. The users can also compete with each other in virtual competitions and define goals to run more often, faster or a longer distance. The Nike+ website displays the data graphically with Adobe Flash.

There is no official API that allows you to use the raw data. Nevertheless the data are sent to the Flash via XML so there is a chance to use them. For PHP Rasmus Lerdorf himself has implemented a class to access these data. The class allows to authenticate a user and fetch the running data of a user in a XML-Format. This class can be found under Nike+ PHP API. To use that class you just have to create an object and pass the user credentials and optional caching parameters:

include("nikePlus.php");
$mynike = new NikePlus("user@domain.de", "password");

After the instantiation the object contains a SimpleXML object with all running information of that user that can be processed by any PHP application. The variables $data, $run, $challenges and $goals hold the information of the user account, runnings, ongoing challenges with other users and the personal goals of a user.
A partial output of the $data variable is shown below and contains among other things the total statistics of a user and the last recent run. The other data are represented in a similar way.

object(SimpleXMLElement)#3 (5) {
  ["userTotals"]=>
  object(SimpleXMLElement)#7 (4) {
    ["totalDistance"]=>
    string(8) "106.5635"
    ["totalDuration"]=>
    string(8) "40500702"
    ["totalRuns"]=>
    string(2) "21"
    ["totalCalories"]=>
    string(4) "5195"
  }  
  ["mostRecentRun"]=>
  object(SimpleXMLElement)#9 (4) {
    ["@attributes"]=>
    array(1) {
      ["id"]=>
      string(10) "1155526254"
    }
    ["startTime"]=>
    string(25) "2008-04-20T10:40:54+02:00"
    ["distance"]=>
    string(6) "6.6107"
    ["duration"]=>
    string(7) "2303090"
  }
}

The Nike+ data can be used to display them on a website or to use them for mash up applications. For example there is already a word press plugin to display the data on a Blog System. Also there is another community called Runner+ which displays the data in a way similar to the Nike website.

Avatar von Stephanie Ehrling

Kommentare

7 Antworten zu „Accessing Nike+ data with PHP“

  1. I wrote something like this in the past that would run when you connected your ipod, it would fetch the raw data from the ipod, upload it to my site via FTP (planned to make it xml webservice but lost time) and then would open iTunes and send the data to nike.

    I was doing this because I wanted to be able to store the data on my own site and show graphs etc. that nike was not doing.

    I was using Platypus and it was Mac only for this reason.

  2. Avatar von Rasmus

    You missed the http://slowgeek.com site which is where I actually use that code.

  3. Nike+ is really high comfort. hope future will bring some bugfixes of it. i can imagine to use it at my projects in future.

  4. Interesting article, unfortunately with my limited php skills I am still stuck! Could you give me any pointers towards actually getting the workout data into a html page?

    Is it just a case of accessing the object for the actual workout data?

    Or am I just in way over my head? :p

    1. You have to fetch the the object (like $mynike from the example) and use echo $mynike->mostRecentRun->distance; for example to print out the distance of your last run. You can access any property of the object like that and use it for your output.

  5. If there a way of uploading my data to the nike website without using itunes. I use winamp to manage my ipod so when i connect it using itunes it says that my ipod is corrupt.

    Thanks in advance.

  6. The service just doesn’t seem to work for me anymore. i always get an error saying something is not available. I figured out a slightly different approach and started a new project called Nike+PHP, can be found at http://nikeplusphp.org

    Similar concept, just easier to use (IMO). Work in progress.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert


Für das Handling unseres Newsletters nutzen wir den Dienst HubSpot. Mehr Informationen, insbesondere auch zu Deinem Widerrufsrecht, kannst Du jederzeit unserer Datenschutzerklärung entnehmen.