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

Web Api integration in .net core to get Activities - Getting insufficient_scope

ANSWERED

Error Detail -

{"errors":[{"errorType":"insufficient_scope","message":"This application does not have permission to access profile data. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}],"success":false}

 

My .Net Code API to get  -

var date = DateTime.Now;
string str = "afterDate='"+ String.Format("{0:yyyy-MM-dd}", date) + "'&sort=desc&limit=40&offset=0";
var client = new RestClient("https://api.fitbit.com/1/user/-/activities/list.json?" + str);
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Basic <Redacted>"); //ClientID:ClientSecret Base64
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");

request.AddParameter("client_id", "<Redacted>");
request.AddParameter("redirect_uri", "http://localhost:8100/stats");
request.AddParameter("scope", "weight location settings nutrition social activity heartrate profile sleep");
IRestResponse response = client.Execute(request);

 

 

Please help to correct this code.

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Hi @AnilSingh ,

 

You don't need a license to access the data. You only need a user's consent.

 

Looking at your post, it looks like you are trying to access your own data, which you can do through any application type as long as you give consent to your application to access your data.

 

If you haven't already done so, I recommend going through your oAuth 2.0 Tutorial at your application settings page at https://dev.fitbit.com/apps/details/<YourClientID>. The tutorial will guide you through your application's authorization process and you'll have to select which data in the authorization page to allow your application access to.

 

Once you've authorized your application to access your data, the following steps will show you how to use your access token and begin making API calls to your account.

 

I hope this helps. Please let me know if you have any additional questions.

View best answer in original post

Best Answer
0 Votes
16 REPLIES 16

I am Getting error when I am calling an API - https://api.fitbit.com/1/user/87ZF3T/activities/list.json?afterDate='2019-07-17'&sort=desc&limit=40&...

 

My Code is -

var date = DateTime.Now;
string str = "afterDate='"+ String.Format("{0:yyyy-MM-dd}", date) + "'&sort=desc&limit=40&offset=0";
var client = new RestClient("https://api.fitbit.com/1/user/-/activities/list.json?" + str);
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Basic <Redacted>"); //clientId:secretId
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");

request.AddParameter("client_id", "<Redacted>");
request.AddParameter("redirect_uri", "http://localhost:8100/stats");
request.AddParameter("scope", "weight location settings nutrition social activity heartrate profile sleep");
IRestResponse response = client.Execute(request);

 

Response Error -

{"errors":[{"errorType":"insufficient_scope","message":"This application does not have permission to access profile data. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}],"success":false}

Best Answer
0 Votes

Hi @AnilSingh,

 

Welcome to the forums!

 

I believe I have responded to you via email, but I'll be happy to post the answer here as well.

 

This error typically occurs when the user you are trying to fetch data from has not given your application consent to extract data from a particular scope. In this case, it looks like the user did not give your application consent to access their profile data on the authorization page during the user consent process.

If the user has not given to access certain scopes, you will not be able to make api calls to fetch data from those resources. You'll need to have the user go through the authorization process again to update their preferences (check the profile scope) in order to make API calls to this resource.

 

I hope this helps. Let me know if you have any questions.

Best Answer
0 Votes

Hi John,


I also tried for single scope (profile) but I got the same error message.
Please investigate and guide me to resolve this issue.
 
Do you want my access detail?
 
Thanks

Best Answer
0 Votes

@AnilSingh I checked the authorized applications for the user ID you provided and saw that your application was not listed as an authorized application to access the data.

 

Could you go through the authorization process again and enable all scopes, then try your request again? If the issue persists, please let me know.

Best Answer
0 Votes

Yes please help me. Till now I'm not able to access the data.

 

Please explain the steps to resolve this issue. If possible at your end please allow to access data.

 

Thank you

Best Answer
0 Votes

Hi JohnFitbit,

 

Do I need a licence key for access the data in my application?

 

Thanks,

Anil

Best Answer
0 Votes

Hi @AnilSingh ,

 

You don't need a license to access the data. You only need a user's consent.

 

Looking at your post, it looks like you are trying to access your own data, which you can do through any application type as long as you give consent to your application to access your data.

 

If you haven't already done so, I recommend going through your oAuth 2.0 Tutorial at your application settings page at https://dev.fitbit.com/apps/details/<YourClientID>. The tutorial will guide you through your application's authorization process and you'll have to select which data in the authorization page to allow your application access to.

 

Once you've authorized your application to access your data, the following steps will show you how to use your access token and begin making API calls to your account.

 

I hope this helps. Please let me know if you have any additional questions.

Best Answer
0 Votes

@JohnFitbit, Thank you very much for your great support. Now, I resolved my issue.

Best Answer
0 Votes
Thank you very much for your great support. Now, I resolved my issue.
Best Answer
0 Votes

@AnilSingh Great! Let me know if you need anything else.

Best Answer
0 Votes

Hi JohnFitbit,

One more thing, I successfully access your all activities APIs but the activates (speed steps, calories, distance, and so on) value getting 0.


Please take a look and get back to me.

 

See the response JSON -

 

Thank You.

Best Answer
0 Votes

@AnilSingh Can you provide me with the endpoint you used and the response you received? If you attached anything to your last post, I am not able to see it.

Best Answer
0 Votes
Hi John,

Thank for your quick response. Please find the below detail.

*GET*
https://api.fitbit.com/1/user/-/activities/list.json?afterDate=2019-07-17&sort=desc&limit=40&offset=...
passed

*Request Headers -*
GET
/1/user/-/activities/list.json?afterDate=2019-07-17&sort=desc&limit=40&offset=0
HTTP/1.1
Host: api.fitbit.com
Accept: */*
User-Agent: Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)
Authorization: Bearer
eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIyMkJKUzciLCJzdWIiOiI4N1pGM1QiLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3NfdG9rZW4iLCJzY29wZXMiOiJyc29jIHJzZXQgcmFjdCBybG9jIHJ3ZWkgcmhyIHJudXQgcnBybyByc2xlIiwiZXhwIjoxNTgxNjA3OTUxLCJpYXQiOjE1ODE1NzkxNTF9.RARaVxCjzZGfby7GYdnqowMnnTAQgofM4pjr-2Whzvw

*Response Headers -*
HTTP/1.1 200 OK
Date: Thu, 13 Feb 2020 07:42:12 GMT
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
CF-Ray: 56452a0d1f06ea40-IAD
Cache-Control: no-cache, private
Content-Language: en
Vary: Origin,Accept-Encoding
Via: 1.1 google
CF-Cache-Status: DYNAMIC
Alt-Svc: clear
Expect-CT: max-age=604800, report-uri="
https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Fitbit-Rate-Limit-Limit: 150
Fitbit-Rate-Limit-Remaining: 150
Fitbit-Rate-Limit-Reset: 1068
X-Frame-Options: SAMEORIGIN
Server: cloudflare

*Response Body -*
{"activities":[{"activeDuration":9000,"activityLevel":[{"minutes":0,"name":"sedentary"},{"minutes":0,"name":"lightly"},{"minutes":0,"name":"fairly"},{"minutes":0,"name":"very"}],"activityName":"Walk","activityTypeId":90013,"averageHeartRate":84,"calories":0,"distance":0,"distanceUnit":"Kilometer","duration":13000,"elevationGain":0,"lastModified":"2020-01-28T10:32:52.000Z","logId":28419872660,"logType":"tracker","manualValuesSpecified":{"calories":false,"distance":false,"steps":false},"originalDuration":13000,"originalStartTime":"2019-10-31T22:38:39.000+05:30","source":{"id":"149168381","name":"Charge
3","trackerFeatures":["VO2_MAX","STEPS","ELEVATION","PACE","DISTANCE","HEARTRATE","GPS","CALORIES"],"type":"tracker","url":"
https://www.fitbit.com/"},"speed":0,"startTime":"2019-10-31T22:38:39.000+05:30","steps":0},{"activeD...
3","trackerFeatures":["SPEED","ELEVATION","DISTANCE","HEARTRATE","GPS","CALORIES"],"type":"tracker","url":"
https://www.fitbit.com/"},"speed":0,"startTime":"2019-10-31T12:16:11.000+05:30"},{"activeDuration":3...
3","trackerFeatures":["VO2_MAX","STEPS","ELEVATION","PACE","DISTANCE","HEARTRATE","GPS","CALORIES"],"type":"tracker","url":"
https://www.fitbit.com/"},"speed":0,"startTime":"2019-10-28T11:23:02.000+05:30","steps":13},{"active...
3","trackerFeatures":["VO2_MAX","STEPS","ELEVATION","PACE","DISTANCE","HEARTRATE","GPS","CALORIES"],"type":"tracker","url":"
https://www.fitbit.com/
"},"speed":0,"startTime":"2019-10-23T10:07:01.000+05:30","steps":0}],"pagination":{"afterDate":"2019-07-17","limit":40,"next":"","offset":0,"previous":"","sort":"desc"}}


Thanks,
Anil
Best Answer
0 Votes

@AnilSingh There doesn't appear to be anything wrong with the API since you were able to receive data for this activity log.

 

After looking at the activity itself, it looks like a Walk activity was started from the device, lasted 9 minutes, but detected no activity. Was the device worn during the activity? It might explain why 0s were returned for steps, distance, and calories.

Best Answer
0 Votes
Yes, John. The device was worn during the activity.

Now, I'm sending the new JSON Response. Please see the walk and run
activity's steps is zero but in my fitbit app I can seen 1,732 steps, 1.26
Km, 14 Mins and so on. Please check and resolve this issue.

Also you can verify using my Fitbit App credential.
anil.singh@steeprise.com/anil@123!

*Response JSON -*
{"activities":[{"activeDuration":5000,"activityLevel":[{"minutes":0,"name":"sedentary"},{"minutes":0,"name":"lightly"},{"minutes":0,"name":"fairly"},{"minutes":0,"name":"very"}],"activityName":"Run","activityTypeId":90009,"averageHeartRate":53,"calories":0,"distance":0,"distanceUnit":"Kilometer","duration":18000,"elevationGain":0,"heartRateLink":"
https://api.fitbit.com/1/user/-/activities/heart/date/2020-02-11/2020-02-11/1sec/time/21:02:18/21:02...
of Range"},{"max":129,"min":92,"minutes":0,"name":"Fat
Burn"},{"max":157,"min":129,"minutes":0,"name":"Cardio"},{"max":220,"min":157,"minutes":0,"name":"Peak"}],"lastModified":"2020-02-14T08:25:53.000Z","logId":28903615852,"logType":"tracker","manualValuesSpecified":{"calories":false,"distance":false,"steps":false},"originalDuration":18000,"originalStartTime":"2020-02-11T21:02:18.000+05:30","source":{"id":"149168381","name":"Charge
3","trackerFeatures":["STEPS","VO2_MAX","PACE","GPS","CALORIES","HEARTRATE","DISTANCE","ELEVATION"],"type":"tracker","url":"
https://www.fitbit.com/
"},"speed":0,"startTime":"2020-02-11T21:02:18.000+05:30","steps":0,"tcxLink":"
https://api.fitbit.com/1/user/-/activities/28903615852.tcx"},{"activeDuration":9000,"activityLevel":...
3","trackerFeatures":["STEPS","VO2_MAX","PACE","GPS","CALORIES","HEARTRATE","DISTANCE","ELEVATION"],"type":"tracker","url":"
https://www.fitbit.com/"},"speed":0,"startTime":"2019-10-31T22:38:39.000+05:30","steps":0},{"activeD...
3","trackerFeatures":["SPEED","GPS","CALORIES","HEARTRATE","DISTANCE","ELEVATION"],"type":"tracker","url":"
https://www.fitbit.com/"},"speed":0,"startTime":"2019-10-31T12:16:11.000+05:30"},{"activeDuration":3...
3","trackerFeatures":["STEPS","VO2_MAX","PACE","GPS","CALORIES","HEARTRATE","DISTANCE","ELEVATION"],"type":"tracker","url":"
https://www.fitbit.com/"},"speed":0,"startTime":"2019-10-28T11:23:02.000+05:30","steps":13},{"active...
3","trackerFeatures":["STEPS","VO2_MAX","PACE","GPS","CALORIES","HEARTRATE","DISTANCE","ELEVATION"],"type":"tracker","url":"
https://www.fitbit.com/
"},"speed":0,"startTime":"2019-10-23T10:07:01.000+05:30","steps":0}],"pagination":{"beforeDate":"2020-02-14","limit":40,"next":"","offset":0,"previous":"","sort":"desc"}}

Thank you,
Anil
Best Answer
0 Votes

Hi @AnilSingh 

 

On 2020-02-11, I think the problem is you recorded the activity on the tracker for too short a period of time.   The smallest intraday interval for activity is 1 min.  However, you recorded the activity on your tracker for 18 seconds.   In the intraday data, we see no data recorded for steps.   My recommendation is to enable the exercise, walk or run for a few minutes, stop the exercise recording and sync your tracker.  I would expect you to see steps.

 

Gordon

 

 

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