Nike API PHP Example

Recently Nike released their developer site to give people a preview and a glimpse into how they will be able to access and export Nike data through their upcoming API. The problem being is that it’s still in development stage, and for users like me, who aren’t part of (or won’t be part of) their Nike+ Accelerator Program, it doesn’t actually give you access.

But it does expose quite a few parts that with a little tinkering, console debugging, and help from the ol’ t’internet you can figure out the core concepts and key attributes and write your own PHP script. It returns the information in lovely JSON format which can easily be used and manipulated to your hearts content.

[php]

$curl_handle=curl_init();
$data = array(‘appid: fuelband’, “Accept: application/json”);
curl_setopt($curl_handle,CURLOPT_URL,’https://api.nike.com/me/sport?access_token={access_token}’);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_HTTPHEADER,$data);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

if (empty($buffer)) {
print “Sorry, something went wrong here”;
} else {
print $buffer;
}

[/php]

Simple hey! The {access_token} is a personal ID related to your account, that you can generate from the Nike Developer Site.

The URL can take various formats, depending what you want to grab, The URL above:

[code]https://api.nike.com/me/sport[/code]

Simply grabs an overview of my activity:

[code]
{
“experienceTypes”: [
“ALL”,
“RUNNING”
],
“summaries”: [
{
“experienceType”: “ALL”,
“records”: {
“lifetimeFuel”: 64631
}
},
{
“experienceType”: “RUNNING”,
“records”: {
“level”: 3,
“lifetimeDuration”: “29:17:42.000”,
“lifetimeGpsRuns”: 29,
“lifetimeHeartActivities”: 0,
“lifetimeAveragePace”: 348832.2388571808
}
}
]
}
[/code]

But you can also use these URL’s to get more information:

  • https://api.nike.com/me/sport/activities
  • https://api.nike.com/me/sport/activities/%activityId%
  • https://api.nike.com/me/sport/activities/%activityId%/gps

The last one giving you full GPS data of an activity.

A big hats off to WotLabs that basically gave me the last piece of the pizzle, the appid.


Posted

in

,

by

Tags:

Comments

One response to “Nike API PHP Example”

  1. cchana Avatar

    I’ve only had a quick look at the API documentation they’ve provided but I must say it looks like an step in the right direction. Liberating data is just as important as collecting it and one of main reasons I myself worked on Nike+PHP.

    The Fuelband line seems to be the focus for things now, but with so many years put behind their other products, it’s not a suprise and I guess they’re very stable.