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

Making a call for heart rate 401 error

Hello everyone,

I am trying to get heart rate data from the fitbit api, but I have some problems. I am using angular 7.

The first step is to authenticate. From the Oauth 2.0 tutorial page, I copied the url specified and I make a GET request. 

What am I supposed to see? From my understanding, I supposed to get a token to use with the next api call where I try to get heart rate data. But when I store the response in a variable and print it, I see no token.

Anyway this GET request shows no errors, but when I try to get heart rate data, I get an 401 error. The url I am using is 

'https://api.fitbit.com/1/user/' + userID + '/activities/heart/date/today/1d.json';

Any ideas? How am I supposed to use the token generated from the authentication call?

Best Answer
0 Votes
1 REPLY 1

Hi @OrestisZekai 

 

Once you execute the /oauth2/authorize endpoint, you should be presented with the scopes page.  You'll enable the specific scopes and press the "Allow" button.  You can replicate this by clicking on the link in the OAuth 2.0 tutorial page.

 

You should be redirected to your callback URL.  The URL will contain either the access_token (Implicit Grant Flow) or a code (Authorization Code Grant Flow).  If using the Authorization Code Grant Flow, your application needs to parse the code out of the URL, execute POST https://api.fitbit.com/oauth2/token specifying the grant_type=authorization_code, and we will provide you with the access_token and refresh_token.

 

Once you have the access token, you can execute the endpoint

 

https://api.fitbit.com/1/user/' + userID + '/activities/heart/date/today/1d.json
Authorization: Bearer <access_token>

 

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