02-03-2016 19:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

02-03-2016 19:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I am using node.js with express, and I am able to login via OAuth2, and recieve a token back. I am then logged in to my app with the proper auth credentials, and I would like to make a simple GET request to the API, but the request I make comes back with:
"GET https://api.fitbit.com/1/foods/30414.json 401 (Unauthorized)"
I have tried multiple different API GET requests, and they all come back with the same 401 error.
Could you possibly give me a working example of a GET request written in javascript? I cannot figure out what headers or parameters I need to attach to my GET request in order to be granted access.
I have tried a few iterations of:
$scope.getFitBitProfile = function (){
$http.get('https://api.fitbit.com/1/foods/30414.json',{
Authorization: 'Bearer <access token I was given back from signing in>'
}).success( function (data) {
console.log(data);
})
.error( function () {
console.log('Search error');
});
}
and it just hits the console.log('Search error') everytime. Any advice?

- Labels:
-
JavaScript
02-06-2016 03:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

02-06-2016 03:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
If you can log in and get an access token but get a 401 when requesting resources it sounds like you need to specify the scope required for the end point you are looking for when getting a request token. Each end point now (for OAuth2) needs to have the specified scope authorized by the user -
https://dev.fitbit.com/docs/oauth2/#scope

