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

Need help getting started with Web API

Hi all, 

I am having trouble understanding how to access the Web API for a university research project. I have participants who are wearing Fitbit Charge 4s for 7 days and nights, and I want to access their intraday movement information (ideally in all 3 dimensions) to generate a measure of movement diversity. And, I am also interested in capturing the sleep metrics data. The Fitbit Charge 4 also calculates sleep stage information using an algorithm. My interest is to see if these metrics can predict depression scores on a standardized measure filled out by participants.

I have gotten permission from Fitbit to access intraday data, however, I am confused re: how to use the Web API. Does the Web API refer to the online Fitbit.com page that I can access through my account? 

Or do I need to somehow create a basic app on the developer page?  

Fitbit is a popular research tool in Psychology and Kinesiology, and so I figure this must have been sorted out before and should be pretty basic. Can someone point me in the right direction re: how to access intraday movement and sleep stage information? 

 

Thanks!

 

Ken

Best Answer
0 Votes
6 REPLIES 6

Hi @data_read_400,

 

Welcome to the forums!

 

If you haven't done so already, please check our Quick Start Guide for using the Web API. Once you register your application, you'll need to provide your contact that approved your request for intraday access with a Client ID. Your application's Client ID can be found at https://dev.fitbit.com/apps under your app details. This will be used to enable the intraday data for your application. 

 

Once Intraday is enabled on your application, you can refer to the following documentation on how to implement the Intraday Timeseries endpoints:

Let me know if you have any additional questions.

Best Answer
0 Votes

Hi John,

 

Okay, I've started back up on this after taking a break for the holidays. I am working on a research project that involves measuring participant sleep and activity levels to see if they can predict depression scores. 

 

I have my own personal Fitbit, and my first step is to use the OAuth 2.0 scheme to request and access my own data. 

 

I do have a registered application, with an OAuth 2.0 Client ID, etc. 

 

I am most experienced programming in R, and I did find this R package that might do the trick: https://github.com/teramonagi/fitbitr

 

So, I am going to try that. Once I've figured out how to pull my own info, then I do have some participants who have worn the Fitbit, and I can send them requests to share their data. I then want to be able to download the data as a file, and to process relevant metrics using an R script.

 

I am hoping to get this figured out this week, so we can move the study forward once classes start back up. Thanks in advance for your help!

 

Ken

Best Answer
0 Votes

hi there:)

Best Answer
0 Votes

Hmmm... I am still wrestling with getting this working.

 

I've got 3 issues. 

 

1) I am having trouble getting fitbitr to load in Rstudio. I've been able to download the files onto my hard drive, and I've tried installing from a .zip, but that hasn't worked. So, I am wrestling with implementation in R. Any suggestions for an easier way to proceed?

 

2) I've been able to use the OAuth 2.0 tutorial page to create an authorization link. Can I send this link to a study participant to authorize participation? I understand their authorization creates a token... but I don't understand how I get a message that they've authorized it. I can see that I could send them to a webpage that would get this data, but I don't know how to do that. 

 

3) I am still figuring out how to make the data request. I get that once the participant authorizes, it returns the OAuth 2.0 Access Token, and I need to get that token, and use that code to make a request, and then the data would be in JSON format, and ideally I would capture in R and export as a .csv.

 

I have found a video of someone using a program called Postman to make these requests, so I guess that's an option, although my preference would be to stick with R.

 

Is there anyone currently using R to extract data from research participants who have  worn the Fitbit for 7 days? I am still looking for help! 

 

Thanks,

 

Ken

Best Answer
0 Votes

Hi all, 

 

Okay, I've managed to get fitbitr working in Rstudio, and was able to generate a local token request... so, I've solved that first issue. 

 

I am going to see if I can access my own data using fitbitr, but I am not sure how to use it to access data from consenting participants. 

 

Cheers,

Ken

Best Answer
0 Votes

Hi @data_read_400,

 

You can check our community resources here, I believe there is a sample code for R.

 

The authorization URL generated by the OAuth 2.0 tutorial is a valid link that you can provide to other Fitbit users as long as your application is set to "client" or "server". If your application is set to "personal", only the owner (you) would be able to consent to share data through this authorization URL.

 

When a Fitbit user consents to share data with your application, your application will need to store that user's access token and refresh token (if you're using the authorization code grant flow), or access token only (if using the Implicit Grant Flow).

 

Could you tell me which OAuth 2.0 flow you're using (authorization code grant flow or implicit grant flow)?

 

After a user consents, you'll be provided with the user's JWT access token, which when parsed, will determine how long the token is active for, the user id of the customer, the client id the token is associated to, and the scopes that the user consented to share. You'll use this access token in the authorization header of your requests to make API calls. 

 

I'm not familiar with R, but hopefully, someone in the community that has used R can pitch in. 

 

 

Best Answer
0 Votes