Nike API PHP Example Feb20

Tags

This Post Was Wrote at

Related Posts

Share This

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:

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.