- Came across a really cool Revolutionary War memorial last weekend not far from where we live. I forget how historic New England is. 2010/07/20
Twitter Feed
- Why on earth would I upgrade, the version I use works just fine. #sarcasm
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
- I drove by and looks like everything at the shoppes is a go. On with movie night. 2010/07/18
Fannation Blog- MLS Rookies, great sign for the future of the league June 1, 2010
Scordit- New Super Mario Bros (Wii) June 25, 2010Wife bought this for me for Fathers day. They did a fantastic job at combining modern graphics and mixing the great classic pieces of all the original Mario Bros games. […]
- New Super Mario Bros (Wii) June 25, 2010
-
Nike+ Latest Run:
Previous Post Getting your Nike+ feed into Wordpress Next Post
Posted: January 21st, 2010 in Web Development. No Comments
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:
- Find your Nike+ ID: First thing you’ll need is your Nike+ ID number. that’s not your login ID btw. It’s a 10 digit number assigned by nikeplus.com. I found mine with the help of this page. Their instructions are actually a little old. But I was able to find that same number from the object code from my old Niki animated mini guy that I put on my old blogspot blog a year ago. There is also a helpful snippit of code you can use for finding it as well.
- Upload Nike+PHP: If you’re using Wordpress, upload nikeplusphp.1.2.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 0123. . . with your own Nike+ ID.
<?php require_once 'nikeplusphp.1.2.php'; $nikePHP = new NikePlusPHP(0123456789, true); ?> - 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:
$np = $nikePHP->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 usage 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 $np['duration'] the $np is whatever the function was assigned to it previously. I used $np because it was on the usage site, I think if you look at that page you’ll see what I mean. 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:
<?php echo $np['distance']; ?></li> - 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.
<h2>Nike+ Latest Run:</h2> <?php require_once 'nikeplusphp.1.2.php'; $nikePHP = new NikePlusPHP(0123456789, true); $np = $nikePHP->basicLastRun(); $minutes = ($np['duration'] % (1000*60*60)) / (1000*60); $pace = $minutes / $np['distance']; ?> <p>Distance: <?php echo number_format( $np['distance'], 2 ); ?> 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 somethign 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.






What are your thoughts? Leave a comment or join the discussion
No comments yet.
Leave a comment