- Snap into a Slim Jim - RIP Macho Man Randy Savage 2011/05/20
Twitter Feed
- RT @badbanana: Maybe if Matthew Broderick showed up to work more often he could afford a proper movie star car.
Podcar News
- Been out of the loop for a while. Busy with some projects. I'm going to take time today though to get caught back up in the world of PRT 2010/03/12
CollinsvilleCT.org
- Heading out with the family to give the new Canton Golf Center mini golf course a try. 2011/12/30
Fannation Blog- MLS Rookies, great sign for the future of the league June 1, 2010
Scordit- Starcraft 2 July 30, 2010Been playing it pretty much non stop after work since it has come out. Crazy awesome game. […]
- Starcraft 2 July 30, 2010
-
Nike+ Latest Run:
Distance: 2.01 Miles
Time: 17.15 Minutes
Pace: 8.51 Minutes per Mile
Previous Post Getting your Nike+ feed into WordPress Next Post
Posted: January 21st, 2010 in Web Development. 4 Comments
*This post has been updated to support the latest version of nikeplusphp (2.0.1). Sorry it was out of date for so long
Nike+ is a system designed by Nike to work with Apple iPod nano, touch, and iPhone 3GS to keep track of your running and a lot more. I’ve been using it for almost two years now and love it. It’s a device that attaches on my iPod nano and gets data from a chip that’s inside my Nike shoes and keeps track of my pace, distance, etc. I can then sync my running data to nikeplus.com where it graphs and keeps track of my running history. The site is ok, it does have its weaknesses. The site is done completely in Flash. Which can be frustrating for a number of reasons.
There are your standard Facebook and Twitter sharing features built into the site, but as far as your data goes, there isn’t a lot you can do with it. When I created my blog my goal was to have all my content available in one place. I wanted to be able to share all my latest data here on my WordPress blog and wanted to customize the look. For the majority of these widgets, it’s achieved through RSS feeds. My running data had no such feed.
I did some reading and found that the Nikeplus.com handled the running data in an XML feed. I would have to find the feed and then get the latest run information to update on my site. One big problem is that XML isn’t allowed to be displayed across different sites or hosts. Meaning if you have an XML file you want to share, you have to host it on your own site. There is a way around that however, you can using server-side language parse an XML feed from one place to make it availble to use on your own project.
After a little digging and a little trial-and-error I found out how to do it. I figured I’d share what I learned, in case others are out there struggling with getting your nike plus data into your own site. Here are the steps:
- Get your nike+ login email & password: Great news, you no longer need your Nike+ ID. Which is good because it was a pain in the butt to find. nikeplusphp 2 now takes your normal log in information
- Upload Nike+PHP: If you’re using WordPress, upload nikeplusphp.2.0.1.php file into your template folder. If you’re not using WordPress, upload it into your project and just keep in mind where you put so you know where it is come time to link to it.
- Add the code to your theme or page: Next thing you need to do is add this code where you want your data to show up. Just make sure to replace the email and password for your own credentials.
require_once 'nikeplusphp.2.0.1.php'; $np = new NikePlusPHP('nike_email@address.com', 'nikepluspassword', true ); (add true on the end like that if you want your data in miles, otherwise false will return data in KM) - Add a function: in that same block of php add a function. There are many to choose from, but in general they will look like this:
$runs = $np->fullRunInfo();There are a few different things you can call here. You can get your profile information, first run, latest run, all runs, runs between, past, or before a specific date. The full list is found here at the Nike+PHP website documentation page.
- Display the data you want: I had actually done pretty well before this point and from the instructions on the Nike+PHP website it showed a function to display the entire array, but I didn’t want that, I wanted just a couple pieces of data. For that you need to pull out that data out by doing something like this $lastrun['duration'] the $lastrun is whatever the function was assigned to it previously. You can pass things into it like ‘runId’, ‘startTime’, ‘distance’, ‘duration’, ‘synctime’, ‘calories’, ‘name’, ‘description’, ‘howFelt’, ‘weather’, ‘terrain’, or ‘equipmentType’ and just echo the result:
$lastrun = $np->basicLastRun(); echo $lastrun['distance']; - Tips: What I described above should give you the basics of pulling the data you want. Thing is though the data probably isn’t what you expect. Duration is measured in milliseconds for example and distance is measured a more precise than you might think. Here are some things that I did to change the milliseconds to minutes, cut off measurements past the 2nd decimal place, as well as figure out my pace.
$distance = number_format( $lastrun['distance'], 2 ); (cuts distance off at 2 decimals) $minutes = ($lastrun['duration'] % (1000*60*60)) / (1000*60); (gives the distance in minutes) $pace = $minutes / $lastrun['distance']; (with distance and minutes we can determine pace)All Together
<?php require_once 'nikeplusphp.2.0.1.php'; $np = new NikePlusPHP('email', 'password', true); $lastrun = $np->basicLastRun(); $distance = number_format( $lastrun['distance'], 2 ); $minutes = ($lastrun['duration'] % (1000*60*60)) / (1000*60); $pace = $minutes / $lastrun['distance']; ?> <p>Distance: <?php echo $distance; ?> Miles</p> <p>Time: <?php echo number_format( $minutes, 2 ); ?> Minutes</p> <p>Pace: <?php echo number_format( $pace, 2 ); ?> Minutes per Mile</p> <p class="credit">Nike+PHP</p>As you can see I had to modify things a bit. First was to change duration to minutes. For that the formula is minutes = (#milliseconds % (1000*60*60)) / (1000*60). To cut off the duration and distance after 2 decimal places I passed the variable into number_format( $variable, 2); that cut off anything past the second decimal. And pace I found by dividing the duration in minutes by the distance.
I hope this has been more helpful and not more confusing. My case was pretty simple, I simply wanted the time and distance of the last workout, but with all the data available, you can really do a lot with it in the way of customizing the showing of your own workout. The creator of this code is really nice and answered my questions via email pretty quick so if you’re really stuck I suggest to shoot him an email. If it’s something simple, like getting something like this to work you can also send me a message or leave a comment on this post and I’ll see if I can help.






Comment by Arnav on February 26, 2011 at 6:59 pm
Can you “Just do it” and make a WordPress compatible plugin for it, since u know ur programming already?
Comment by Bryan Williams on March 3, 2011 at 11:06 am
When I first wrote this post I didn’t have any experience making WordPress plugins. Since then I’ve built a lot of custom plugins but just for my own use. It’s very likely that someone has already beat me to it, but maybe if I get some free time I should make a more plug and play method. This post and method actually needs to be updated. The Nike+ php project has updated their code since I wrote this so I need to look into updating the post and my sidebar as well.
Comment by Bryan on March 10, 2011 at 9:42 am
I updated the post to support Nikeplusphp 2.0.1, sorry for anyone who was trying the old instructions on the new version.
Comment by cchana on January 19, 2012 at 1:24 am
Great post Bryan, nice to see the code being used. I’ve recently updated to 3.0 which returns a lot more data, but is easier to use imo. @Arnav, I’m planning a WordPress plugin, just haven’t decided on exactly what it should return just yet!