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

Where can I find libraries for using the Fitbit Web API?

Fitbit does not have official libraries for using its Web API. The Fitbit Web API has a common implementation of the OAuth 2.0 specification. You don't need a Fitbit-specific library to use the Fitbit Web API. Instead, we recommend that you use the best OAuth 2.0 or HTTP client library available for your platform.

 

If you don't have a favorite OAuth 2.0 or HTTP library yet, we've listed some that people have told us worked for them at https://dev.fitbit.com/docs/community-resources/ .

 

If you have a library that has worked well for your or a great tutorial for using a library with the Fitbit Web API, please let us know!

Best Answer
5 REPLIES 5

I've developed a nodejs API wrapper for the web API here: https://github.com/jbw/hypertonic

Best Answer
0 Votes

Hi @jasonbwatson, I'm developing an iOS Application and want to integrate some sensors like accelerometer , gyroscope and many other. How can I get there API's so that I could get data in my app

Best Answer
0 Votes

These are all very old and do not provide an easy example using JavaScript without node.js additions. As a person not familiar with the javascript protocol I've found this task extremely difficult. It would be very easy surely for someone to just post an example using JS. 

 

Here's one that I can't get to work (yet!).

 

<script type="text/javascript">

function getAuthCode(url) {
// Information from Fitbit Developer site
window.location.assign(url);
}

var OAuthTwoClientID = "myClientID";
var ClientOrConsumerSecret = "mySecret";

var first;
var last;
var code_url;
var access_token;
var dataToGet;
var getURL;
var HR;

// Fitbit URLs
var TokenURL = "https://api.fitbit.com/oauth2/token";
var RedirectURL = "my redirectURL";
var urlCode = "coded version";

// Results required from Fitbit
var act = 'activity';
var hr = 'heartrate';
var sl = 'sleep';

var AuthCode1 = "https://www.fitbit.com/oauth2/authorize?response_type=token";
var AuthCode2 = "&client_id=" + OAuthTwoClientID + "&redirect_uri=" + urlCode;
var AuthScope = "&scope=" + act + "%20" + hr + "%20" + sl;
var time = "&expires_in=31536000";

// Form URL to obtain Authorization Code
var url = AuthCode1 + AuthCode2 + AuthScope + time;

</script>

<input type="button" value="Press Here to Get Fitbit Data" onclick = "getAuthCode(url)">

<script type="text/javascript">
document.write("URL: " + url + "\n" );

code_url = window.location.href;
document.write("code_url: " + code_url + "\n");

// var access_token = code_url.split("#")[1].split("=")[1].split("&")[0];

// var userId = code_url.split("#")[1].split("=")[2].split("&")[0];

first = code_url.indexOf('=') + 1;
document.write("first: " + first + "\n");
last = code_url.indexOf('#');
document.write("last: " + last + "\n");

access_token = code_url.substring(first, last);
document.write("Auth Code is: " + access_token + "\n");


document.write("access_token: " + access_token + "\n");
document.write("userId: " + userId + "\n");


var xhr = new XMLHttpRequest();

var getDataURL = 'https://api.fitbit.com/1/user/';
var beginDate = '2019-03-20';
// var endDate = '2019-04-20';
dataToGet = '/activities/heart/date/' + beginDate + '/1d.json';
getURL = getDataURL + OAuthTwoClientID + dataToGet;

document.write("getURL: "+getURL);

xhr.open('GET', getURL);
document.write(access_token + "\n");
xhr.setRequestHeader("Authorization", 'Bearer ' + access_token);
xhr.onload = function() {
document.write(xhr.responseText + "\n");
document.write(xhr.status);

if (xhr.status === 200) {
var HR = xhr.responseText;
console.log(HR);
document.write(HR);
}
};

xhr.send()

 


</script>

Best Answer
0 Votes

Hey @JeremiahFitbit, I know this is a bit beyond the original post but in case anyone still checks this, just wanted to add my own Python implementation of the web API into the fray: https://github.com/kcinnick/fitnick .

Best Answer
0 Votes

Hi, I just to inform potential R users that I've created an R package fitbitViz that uses Elevation data and 3-dimensinal maps.

Best Answer
0 Votes