09-22-2016 07:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-22-2016 07:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Anyone have a working tutorial of how to use the api to get users heart rate data?
Answered! Go to the Best Answer.
Accepted Solutions
10-03-2016 14:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



10-03-2016 14:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
What is does the body of the request that returned a 401 say?

10-04-2016 11:22 - edited 10-04-2016 11:25
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-04-2016 11:22 - edited 10-04-2016 11:25
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Its working now. Graph n all. Thanks. I just had to allow access to the app.

09-22-2016 10:45
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



09-22-2016 10:45
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Check out the Community Resources page in the docs.

09-28-2016 08:29 - edited 09-28-2016 08:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-28-2016 08:29 - edited 09-28-2016 08:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Jeremiah,
Hello from Ireland. Im trying to register my app. I'm using your javascript example from the community resources. Which url is the callback url? and how do I find mine? I really just need my own heart rate data for now. If the callback url consists of tokens and ids, how do I find this information.
Thanks,
Eoghan Hynes.

09-29-2016 07:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-29-2016 07:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Ah, never mind, I seem to have firgured it out.

10-03-2016 09:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-03-2016 09:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi,
Masters student, thesis project. Trying to access my personal heart rate data...
My App: https://dev.fitbit.com/apps/details/2282KN
Im trying to use your javascript example to get my personal heart rate data:
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>Fitbit Web API demo</title>
<script src="https://www.gstatic.com/charts/loader.js"></script>
<script>google.charts.load('current', {'packages':['line']});</script>
</head>
<body>
<p>hello world</p>
<div id="chart"></div>
<script>
console.log("begin");
// If user hasn't authed with Fitbit, redirect to Fitbit OAuth Implicit Grant Flow
var fitbitAccessToken;
if (!window.location.hash) {
window.location.replace('https://www.fitbit.com/oauth2/authorize?response_type=token&client_id=2282KN&redirect_uri=http%3A%2F...');
} else {
var fragmentQueryParameters = {};
window.location.hash.slice(1).replace(
new RegExp("([^?=&]+)(=([^&]*))?", "g"),
function($0, $1, $2, $3) { fragmentQueryParameters[$1] = $3; }
);
fitbitAccessToken = fragmentQueryParameters.access_token;
console.log("explicit token "+fitbitAccessToken);
}
// Make an API request and graph it
var processResponse = function(res) {
if (!res.ok) {
throw new Error('Fitbit API request failed: ' + res);
}
var contentType = res.headers.get('content-type')
if (contentType && contentType.indexOf("application/json") !== -1) {
return res.json();
console.log("data received");
} else {
throw new Error('JSON expected but received ' + contentType);
}
}
var processHeartRate = function(timeSeries) {
return timeSeries['activities-heart-intraday'].dataset.map(
function(measurement) {
return [
measurement.time.split(':').map(
function(timeSegment) {
return Number.parseInt(timeSegment);
}
),
measurement.value
];
}
);
}
var graphHeartRate = function(timeSeries) {
console.log(timeSeries);
var data = new google.visualization.DataTable();
data.addColumn('timeofday', 'Time of Day');
data.addColumn('number', 'Heart Rate');
data.addRows(timeSeries);
var options = google.charts.Line.convertOptions({
height: 450
});
var chart = new google.charts.Line(document.getElementById('chart'));
chart.draw(data, options);
}
fetch(
'https://api.fitbit.com/1/user/-/activities/heart/date/2016-10-01/1d/1sec/time/09:00/16:00.json',
//'https://api.fitbit.com/1/user/-/activities/heart.json',
{
headers: new Headers({
'Authorization': 'Bearer ' + fitbitAccessToken
}),
mode: 'cors',
method: 'GET'
}
).then(processResponse)
.then(processHeartRate)
.then(graphHeartRate)
.catch(function(error) {
console.log(error);
});
</script>
<!--<script src="./boot.js"></script>-->
</body>
</html>
Hosting on amazon: http://ec2-52-212-2-202.eu-west-1.compute.amazonaws.com/index.html
Getting error 401 in browser console log. Can you check if my app is set up ok and my urls are ok. Im not sure what im doing wrong. Do I have intra day access permission?
Would appreciate any help,
Thanks,
Eoghan Hynes.

10-03-2016 14:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



10-03-2016 14:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
What is does the body of the request that returned a 401 say?

10-04-2016 11:22 - edited 10-04-2016 11:25
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-04-2016 11:22 - edited 10-04-2016 11:25
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Its working now. Graph n all. Thanks. I just had to allow access to the app.

10-06-2016 04:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-06-2016 04:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Jeremiah,
I can get the heart rate data fine using your javascript example but I would like to get other scopes now such as sleep and weight etc.
How do I do this in Javascript. I tried:
'https://api.fitbit.com/1/user/-/activities.json'
which in the console log gives:
data received: function json() { [native code] }
&
'https://api.fitbit.com/1/user/-/activities/sleep/date/2016-10-03/1d/1sec/time/12:00/01:00.json'
which gives:
GET https://api.fitbit.com/1/user/-/activities/sleep/date/2016-10-03/1d/1sec/time/12:00/01:00.json 400 ()
boot.js:96 Error: Fitbit API request failed: [object Response]
at processResponse2 (http://ec2-52-212-2-202.eu-west-1.compute.amazonaws.com/js/boot.js:71:15)
What URLs can I use to get these scopes?

10-06-2016 11:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



10-06-2016 11:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
You'll need to request the correct time series endpoint. These are documented at https://dev.fitbit.com/docs/activity/#activity-time-series .

10-09-2016 13:04
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-09-2016 13:04
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Excellent. Thank you. Now I can get all intra day data using the correct endpoints, eg:
var url = "https://api.fitbit.com/1/user/-/activities/calories/date/2016-10-08/1d/15min/time/09:30/19:00.json"
which is processed using a javascript function like :
var processCalories = function(timeSeries) {
return timeSeries['activities-calories-intraday'].dataset.map(
function(measurement) {
return [
measurement.time.split(':').map(
function(timeSegment) {
return Number.parseInt(timeSegment);
}
),
measurement.value
];
}
);
}
But for non intraday values, like sleep logs:
GET https://api.fitbit.com/1/user/28H22H/sleep/date/2014-09-01.json
How do I parse or format this kind of response? It's obviously gonna be in a different format from intra day but I cant tell from the example in the community resources how to deal with it corretly. Could you give me an example?
I appreciate all of your help so far.
Thanks again.

