Nike+PHP Get your data from Nike+

Nike+PHP

Nike+PHP is PHP class that gets you your data from the Nike+ website, including activities, all time statistics and some aspects of NikeFuel. All you need to get started is PHP 5 with cURL and JSON.

Follow Nike+PHP on twitter and Google+.

Donate

If you would like to show some support for the project, why not buy me a beer, a donut or an energy drink? Please feel free to .

Donate to the Nike+PHP project

Changes from v4.4+

To make Nike+PHP more consistent with Nike+ there have been small changes to the code. From version 4.4+ private methods and variables now begin with an underscore and instead of run and runs, items are now referred to as either an activity or activities.

Please check the documentation and examples for more information.

Download v4.5.1

Nike+PHP is now hosted on this domain. Download the file using the link above and remove the .txt extension.

Documentation

There are a number of things you can do with Nike+PHP, the first thing you need to do is login:

<?php
  require_once 'nikeplusphp.4.5.1.php';
  $n = new NikePlusPHP('email@address.com', 'password');
?>

Once you've successfully logged in, you can call any of the following public methods.

Get Data

Friendly methods

Private methods

Known issues

  1. Changing your username works internally for the Nike+ website, but doesn't always work for Nike+PHP.
  2. If you don't have a country set, the data returned cannot be decoded correctly. The best way around this is to make sure you have a complete profile.
Advertisement

Examples

To help you get started, here are some examples of how to use Nike+PHP.

Activity count

Count how many activities you have recorded with Nike+

<?php
  require_once 'nikeplusphp.4.5.1.php';
  $n = new NikePlusPHP('email@address.com', 'password');
  $activites = $n->activities();
  echo count($activities);
?>

From version 4.2, the method returns an array of objects, rather than an object returning an array of objects.

Get activity info

Get the information about a specific activity.

<?php
  require_once 'nikeplusphp.4.5.1.php';
  $n = new NikePlusPHP('email@address.com', 'password');
  $activity = $n->activity($activityId);
  var_dump($activity);
?>

From version 4.4, the method returns just the data, rather than an array of one item that then contains the data.

Get GPS data

Get the GPS data for an activity, if available.

<?php
  require_once 'nikeplusphp.4.5.1.php';
  $n = new NikePlusPHP('email@address.com', 'password');
  $activity = $n->activity($activityId);
  var_dump($activity->activity->geo);
?>

Distance covered (Km)

The distance you have covered using Nike+, always returned in Km.

<?php
  require_once 'nikeplusphp.4.5.1.php';
  $n = new NikePlusPHP('email@address.com', 'password');
  $activities = $n->allTime();
  echo $activities->lifetimeTotals->distance;
?>

Distance covered (Miles)

The distance you have covered using Nike+, always returned in Km, but converted into miles (2d.p.).

<?php
  require_once 'nikeplusphp.4.5.1.php';
  $n = new NikePlusPHP('email@address.com', 'password');
  $activities = $n->allTime();
  echo $n->toMiles($activities->lifetimeTotals->distance);
?>

Calories burned

The calories you have burned using Nike+.

<?php
  require_once 'nikeplusphp.4.5.1.php';
  $n = new NikePlusPHP('email@address.com', 'password');
  $activities = $n->allTime();
  echo $activities->lifetimeTotals->calorie;
?>

Activity duration (HH:MM:SS)

The duration of your last activity.

<?php
    require_once 'nikeplusphp.4.5.1.php';
    $n = new NikePlusPHP('email@address.com', 'password');
    $activity = $n->mostRecentActivity();
    echo $n->formatDuration($activity->activity->metrics->duration);
?>

Calculate average pace in time/km (HH:MM:SS)

There are a few ways to calculate your pace, depending on what units you want use. This first example shows how to get the pace in km.

<?php
    require_once 'nikeplusphp.4.5.1.php';
    $n = new NikePlusPHP('email@address.com', 'password');
    $activity = $n->mostRecentActivity();
    echo $n->calculatePace($activity->activity->duration, $activity->activity->distance);
?>

Calculate average pace in time/miles (HH:MM:SS)

There are two ways to calculate the pace of a activity in miles, depending on what you pass through. This first example works by setting $toMiles to true.

<?php
    require_once 'nikeplusphp.4.5.1.php';
    $n = new NikePlusPHP('email@address.com', 'password');
    $activity = $n->mostRecentActivity();
    echo $n->calculatePace($activity->activity->duration, $activity->activity->distance, true);
?>

Calculate average pace in time/miles (HH:MM:SS)

This second example works by setting the $distance to reflect the distance of the activity in miles.

<?php
    require_once 'nikeplusphp.4.5.1.php';
    $n = new NikePlusPHP('email@address.com', 'password');
    $activity = $n->mostRecentActivity();
    echo $n->calculatePace($activity->activity->duration, $n->toMiles($activity->activity->distance));
?>

Used by

Below you will find examples of sites or products that use the Nike+PHP code.

Help & contribute

If you need help using Nike+PHP or if you would like to contribute to the project, please feel free to send feature requests or contributions to hello@charanj.it

Here are those that have already contributed to or inspired the project:

To do

As well as looking for suggestions for features, which you can submit to the email address above, I have now included a list of things I have to do on the project and features I would ultimately like to introduce.

Buy Nike+ products

Nike sell a range of products to compliment the Nike+ service, including running shoes, GPS watches and wristbands.

 Apple & mobile

You can purchase Nike+ compatible iPods from Apple, Nike+ music from iTunes and mobile apps from the App Store and Google Play.

Other retailers

You can also buy relevant products from the stores below:

Cookies

This website does not knowingly drop any of it's own cookies, the only cookies used on this site are dropped by third parties and used to power analytics, advertising and social network widgets.

Service Cookie Purpose
Google Analytics Visitor tracking
Tradedoubler (Apple / Nike) Advertising
Google Adsense Advertising
Google+ Social networking
Facebook Social networking
Twitter Social networking
AddThis Social networking