Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Pulling Data from multiple trackers (PHP)

Hi,

 

I am a PHP developer and I am wondering about pulling data from multiple fitbit trackers with a PHP web application. Basically we are looking at purchacing trackers and issuing them to each member of our football team. The club would own the trackers and loan them out to players for a period where we would then track their distance and sleep stats.

 

As it stands I have written a basic PHP application that stores basic player data (weight, height, training attendance etc.) I am wondering if is is possible / difficult to extend this PHP application to pull in data from the fitbit trackers we will be providing the players with.

 

I am just wondering if there are any issues with this plan before we invest. Can multiple trackers be registered to the club account? Sync'd with the one device?

 

If any one has gone down this route and can point me to an example even better!

 

Many thanks,
Sean

 

Best Answer
0 Votes
13 REPLIES 13

You can develop an application that may request access to as many trackers as you want.

As long as fitbit's user who owns tracker grants access(via oauth 1.0a process) for your app to read/write his data you should be able to get all the functionality you need.

 

Please read more at: https://wiki.fitbit.com/display/API/Fitbit+API

Ivan Bahdanau
Senior Software Developer at Fitbit
Best Answer

Just in case it is not clear, although Fitbit devices use BLE (Bluetooth Low Energy) for communications, they use a proprietary protocol and not any of the BT standardized profiles.  So you can't expect to exchange data directly with the device.  However, they have a very robus developer's API, including being able to "subscribe" to specific devices.  Hence, as soon as they sync your server can be notified and you can collect the data.  (Since this question is asked on the Web API forum, I supposed you already knew that...)

 

But the second thing to understand for planning purposes, is to my knowledge each device will need to be registered to a unique email address.  To my knowledge, all the stats are really tied to an email address and not a device ID.  So if you don't want to use each players' own email, you'll need to create email addresses at your club's domain even if something like "device0001@myfootballclub.org" and register the devices against those.

 

If you also are interested in analyzing stats like steps and Very Active Minutes during specific time frames (games, practices, etc) you'll want to apply for Partner API access to the "intra-day" statistics.  This would let you obtain minute by minute activity levels for each player, without them having to start / stop activity mode on each device.  Without Partner level permissions, you can only get daily totals and activities which are explicitly logged.

 

Your other question is if they can be synced with one device.  To my knowledge, a mobile phone can only sync one specific device.  However, a laptop or other computer with the USB dongle will auto-sync any Fitbit which comes in range of the dongle.  Think of it as a mini hot spot for collecting Fitbit data and passing it to Fitbit's servers.  You only need to have them walk within range of a computer running the Fitbit Connect software as frequently as you want data.  Each device will keep per minute detail for up to 7 days between syncs, if they don't sync to their personal phone.  (After 7 days, it keeps up to 30 days of summary stats if you don't care about intra-day detail.)

 

Bottom line is yes, it is doable provided you sync through a USB dongle on a computer, and create an email for each device.  I'd also suggest requesting Partner API access if you want to examine stats from practices and games.

Best Answer

You would need 1 user account per device (though a user can replace a device at any time). Each user would need to authorize your application to access their data.

 

If this is something where your club would control the user account and the device, perhaps you might be interested in a product called Fitabase. It's designed for researchers, but it sounds like you have a similar use case.

Best Answer

Do we get the calories burned categorized by Activity Name? or we get only the total calories burned for a particular day?

 

Can any one, please clarify on this! Much Appreciated your help!

Best Answer
0 Votes

Thanks that is very helpful.

 

One question with regard to syncing multiple devices. The ideal scenario would be to leave a laptop with dongle in the changing room where all players with fitbit bracelets would congregate post a couple of times per week and devices would sync automatically.

 

Is it that simple though? Or in order for it to sync do you have to login for each individual device or swap in the dongle associated with a particular bracelet?

Best Answer
0 Votes

It is indeed that simple.  A USB dongle will auto-sync any Fitbit device which comes in range, no login required.  (For the record, that is NOT true of syncing via a mobile device -- just the USB dongle.)

 

The device must have been previously registered with a Fitbit account, but the dongle will know nothing about the device or who is is registered to.  It just acts as a pass-thru to the Fitbit server.  The laptop will need an active internet connection however.

Best Answer



 i use curl and  php as the classes provided on api tutorial page does not have  a facility to indicate proxy protected internet access on my developement server.


Successfully got temporary  token  and temporary secret,
but when https://api.fitbit.com/oauth/access_token  , i get invalid signature , my question is what is the exact combination to get valid fitbit signature. so i am unable to get the final permanent token and permanent secret.


Thanks for your time,

 

Regards,

Irfan Ahmed

 


   
$url = "https://api.fitbit.com/oauth/access_token";

$oauth = array( 'oauth_consumer_key' => $consumerkey,
                /*'oauth_consumer_secret' => $consumersecret ,*/
                'oauth_nonce' => time(),
                'oauth_signature_method' => 'HMAC-SHA1',
                'oauth_timestamp' => time(),
                'oauth_token'=> $_REQUEST['oauth_token'],
                'oauth_verifier'=> $_REQUEST['oauth_verifier'] ,
                 /*'oauth_callback' => 'https://socialuat.dpworld.com/completeAuthorization.php',*/
                'oauth_version' => '1.0'
                );
$base_info = buildBaseString($url, 'POST', $oauth);
$composite_key = rawurlencode($consumersecret) .'&'. rawurlencode($fitbit_temporary_secret_B).'&';
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$oauth['oauth_signature'] = $oauth_signature;
 

$header = array( buildAuthorizationHeader($oauth), 'Expect:');
$options = array( CURLOPT_HTTPHEADER => $header,
                  CURLOPT_HEADER => false,
                  CURLOPT_URL => $url,
                  CURLOPT_RETURNTRANSFER => true,
                  CURLOPT_SSL_VERIFYPEER => false,
                   CURLOPT_PROXY=> $PROXY_IP,
                  CURLOPT_PROXYPORT=> $PROXY_PORT,
                  CURLOPT_FOLLOWLOCATION=>1
                  
                  );  
                  
                  
$feed = curl_init();
curl_setopt_array($feed, $options);
$responsetoken_E_string = curl_exec($feed);
curl_close($feed);

 

 

Best Answer
0 Votes

Please follow step 8 at this tutorial: https://dev.fitbit.com/apps/oauthtutorialpage

 and compare signature that your code generates with signatures that tutorial generates.

Your code should be generating the same signatures as there are in this tutorial.

 

Also note, that in order to make spte 8 work properly you'll need to enter all required data in steps 1-7.

Ivan Bahdanau
Senior Software Developer at Fitbit
Best Answer
0 Votes

thanks for the reply

 

the signature is not matching for me ,as timestamps are different from the tutorial page and my php generated requests.

 

yes for step 8 , what is the combination of the hash as it is mentioned ?

 

 

"Since the signature is dependent on your client (consumer) secret + access token secret and base string, "

 

  in my signature generation code what is the mistake ?.

 

regards

Irfan Ahmed

 

 

Best Answer
0 Votes

You can enter any timestamp in tutorial manually so just enter the same timestamp that is generated by your code.

Please continue playing with tutorial page and make sure your app generates the same signature as this tutorial page.

Until your code generates the same signature as tutorial page that means you have a mistake in your code.

Ivan Bahdanau
Senior Software Developer at Fitbit
Best Answer
0 Votes

SOLVED

 

thanks for the suggestion, i have resolved the last mile permanent token fetch,

1. altered the paprameters order of base string

2.  consumer key as $composite_key = rawurlencode($consumersecret) .'&'. rawurlencode($fitbit_temporary_secret_B);

 

$oauth = array( 'oauth_consumer_key' => $consumerkey,

    'oauth_token'=> $_REQUEST['oauth_token'],
                /*'oauth_consumer_secret' => $consumersecret ,*/
                'oauth_nonce' => time(),
                'oauth_signature_method' => 'HMAC-SHA1',
                'oauth_timestamp' => time(),
            
                'oauth_verifier'=> $_REQUEST['oauth_verifier'] ,
                 /*'oauth_callback' => 'https://socialuat.dpworld.com/completeAuthorization.php',*/
                'oauth_version' => '1.0'
                );
$base_info = buildBaseString($url, 'GET', $oauth);
$composite_key = rawurlencode($consumersecret) .'&'. rawurlencode($fitbit_temporary_secret_B);

Best Answer
0 Votes

Hi,

     We have same scenario.. We would be providing trackers to our players to monitor their activities.. So can we have all the player trackers tied up with one registered APP in fitibit.. If so, how can we do that?? How can i add all the trackers to one registered APP??

 

 

Thank you

 

Regards,

Shalini

Best Answer
0 Votes

Hi @shalinikrish ,

 

The trackers are actually tied to the Fitbit user's account, not your application.  When the Fitbit user signs up with your application, they will authorize to share their data.  Your application will be given an access token containing the user's Fitbit ID and the data they authorized to share with your application.

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes