Nike+PHP v3 is the smallest version of Nike+PHP, and was previously known as Nike+PHP Lite. This version gives you access to everything Nike provides in their XML feeds.
This version has fewer calls, has a smaller footprint than before but provides everything that is available from the Nike+ service.
Download
Nike+PHP can be found over on Google Code, from there you can download the source code and raise any issues.
Documentation
Nike+PHP's methods return a SimpleXMLElement object or throw an appropriate exception.
On this page, I'll walk you through initializing the class and walk through all of the public methods.
Examples
If you'd like some help getting to grips with Nike+PHP, take a look at some examples.
Exceptions
From version 3.0 onwards, Exceptions are thrown when an error is encountered, rather than just echoing a string and returning false. The documentation for Exceptions on the official PHP website explains how to handle them using a try catch statement, or see the example below.
Index
- Initializing
- profile()
- getRuns()
- getRun()
- getPersonalRecords()
- getGoals()
- getCompletedGoals()
- getUserEvents()
- getTotalDistance()
- getTotalTime()
- getTotalCalories()
- getNumberOfRuns()
- toMiles()
- Error handling
Back to top
Initializing the class
To get started, include the Nike+PHP class, and start the class:
<?php
require_once 'nikeplusphp.3.0.1.php';
$np = new NikePlusPHP('nikeEmail@address.com', 'nikePlusPassword');
?>
Parameters:
- Email address you use to login to the Nike+ service
- Password for the Nike+ password
profile()
It's possible to download your Nike+ profile, you can get it by calling the following method:
$profile = $np->profile();
No parameters required for this function to run.
getRuns()
Returns data for each of your runs that have been uploaded to Nike+
$runs = $np->getRuns();
No parameters required for this function to run.
getRun($runId, $internalCall)
Returns all of the data for a specific run:
$run = $np->getRun($runId);
Parameters:
- You must pass the ID of a run
- An option to flag when calls are made from within another function, rather than called explicitly (optional)
getPersonalRecords()
Returns your personal records:
$personalRecords = $np->getPersonalRecords();
No parameters are required for this function to run
getGoals()
Returns your goals:
$goals = $np->getGoals();
No parameters are required for this function to run
getCompletedGoals()
Returns your completed goals:
$goals = $np->getCompletedGoals();
No parameters are required for this function to run
getUserEvents()
Returns your events:
$events = $np->getUserEvents();
No parameters are required for this function to run
getTotalDistance()
Returns the total distance covered using Nike+:
$events = $np->getTotalDistance();
No parameters are required for this function to run
getTotalTime()
Returns the total time spent running using Nike+:
$events = $np->getTotalTime();
No parameters are required for this function to run
getTotalCalories()
Returns the number of calories burned using Nike+:
$events = $np->getTotalCalories();
No parameters are required for this function to run
getNumberOfRuns()
Returns the number of runs made using Nike+:
$events = $np->getNumberOfRuns();
No parameters are required for this function to run
toMiles()
Converts a distance from the default Km in to miles:
$miles = $np->toMiles($distance);
Parameters
- A distance is required to be converted
Error handling
Using a try catch statement, you can handle the Exceptions thrown.
Exceptions are thrown for general errors, ErrorExceptions are thrown when the returned value is invalid or, in the case of XML, unreadable.
The example below is for catching exceptions when initializing the class.
<?php
require_once 'nikeplusphp.3.0.1.php';
try {
$np = new NikePlusPHP('nike_email@address.com', 'nikepluspassword');
} catch(Exception $e) {
echo $e->getMessage();
}
?>
The example below is for catching exceptions when using one of the methods.
<?php
try {
echo $np->getNumberOfRuns();
} catch(Exception $e) {
echo $e->getMessage();
}
?>
Catching exceptions in this way allows you to handle errors and have complete control over how your application/website works.
The future
Feature requests and contributions are encouraged, please tweet or email through any requests, suggestions or improvements you may have for the project.

