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

403 Error insufficient_permissions(sometimes)

Hi,

 

I'm getting a 403 Error  {"errorType":"insufficient_permissions","message":"API client is not authorized by the resource owner to access the resource requested. ...

 

There are a couple things though. Maybe 1/4 times I make the requests, it goes through.

 

And then part of the code is pulling data for the current user which works, but as soon as I replace the "-" with my own user ID that I'm logged in to, I get the 403 error again. Also, my privacy settings are all set to anyone at the moment.

 

So for example:

var settings4 = 
       	{
           	"async": true,
           	"crossDomain": true,
           	"url": "https://api.fitbit.com/1/user/4VHYJ9/activities/distance/date/" + dataStartDate + "/today.json",
           	"method": "GET",
           	"headers": {
                "authorization": "Bearer " + newAccessToken
          	}
        }
      	$.ajax(settings4).done(function (response4) {
		console.log(response4);
		for (i = 0; i < response4["activities-distance"]["length"]; i++) { 
			totalDistanceCounter = totalDistanceCounter + parseInt(response4["activities-distance"][i]["value"]);
 		}
   			
    	       $("#FCPTMiles").append(totalDistanceCounter + " miles");
    	    

   		console.log(totalDistanceCounter);
	});   			       	
var settings5 =		// Get total calories
       	{
           	"async": true,
           	"crossDomain": true,
           	"url": "https://api.fitbit.com/1/user/-/activities/calories/date/" + dataStartDate + "/today.json",
           	"method": "GET",
           	"headers": {
                "authorization": "Bearer " + newAccessToken
           	}
        }
      	$.ajax(settings5).done(function (response5) {
		console.log(response5);
		for (i = 0; i < response5["activities-calories"]["length"]; i++) { 
			totalCaloriesCounter = totalCaloriesCounter + parseInt(response5["activities-calories"][i]["value"]);
   		}
   		console.log(totalCaloriesCounter);
    	        $("#FCPTCalories").append(totalCaloriesCounter + " calories");
});

So in the first request, I replaced the '-' with my own user ID and the account I'm logged in to. The first request receives a 403 and the second requests works, so I know the auth token is correct.

 

I was also changing with my privacy settings to test things, but it's all been set to anyone for at least 30 minutes now.

 

I'm fairly new to even software development, so any advice or help is much appreciated. Thanks!

Best Answer
0 Votes
0 REPLIES 0