Bruce Gust
asked on
Someone who's worked with the Fitbit API knows the answer to this question...
I'm using "npm fitbit-node" and I am poised on the threshold of great things!
Here's the "app.js" file and I've emboldened that section of the code that I've got a question about:
Smell that? That's the aroma of success! After I've gone through the process of logging in, I get my call back and it looks like this:
Outstanding! But...
If I want heart beat or activity log, I'm stuck because all I've got here is profile info.
According to https://dev.fitbit.com/build/reference/web-api/user/, I can get everything that I need, but I need the "client-id..."
GET https://api.fitbit.com/1/user/[user-id]/profile.json
According to this site, the user-id is something I can access from the profile end point, but I don't see it anywhere in the json that gets returned when I ask specifically for "profile.json" (the json that I've got above).
So,, my question is: Where do I get the client-id from? Every URL that contains the info I need requires that piece of info and I'm thinking that someone who's worked with the Fitbit API probably knows exactly where I need to be looking.
Thoughts?
Here's the "app.js" file and I've emboldened that section of the code that I've got a question about:
// initialize the express application
const express = require("express");
const app = express();
// initialize the Fitbit API client
const FitbitApiClient = require("fitbit-node");
const client = new FitbitApiClient({
clientId: "CLIENT_ID", //client_id
clientSecret: "CLIENT_SECRET", //client secret
apiVersion: '1.2' // 1.2 is the default
});
// redirect the user to the Fitbit authorization page
app.get("/authorize", (req, res) => {
// request access to the user's activity, heartrate, location, nutrion, profile, settings, sleep, social, and weight scopes
res.redirect(client.getAuthorizeUrl('activity heartrate location nutrition profile settings sleep social weight', 'http://localhost:3000/callback')); //callback url
});
// handle the callback from the Fitbit authorization flow
app.get("/callback", (req, res) => {
// exchange the authorization code we just received for an access token
client.getAccessToken(req.query.code, 'http://localhost:3000/callback').then(result => { //callback url
// use the access token to fetch the user's profile information
[b]client.get("/profile.json", result.access_token)[/b]
[u]//client.get ("/1/user/[user-id]/[resource-path]/date/[date]/[period].json", result.access_token)[/u]
.then(results => {
res.send(results[0]);
console.log(results[0].user.age);
}).catch(err => {
res.status(err.status).send(err);
});
}).catch(err => {
res.status(err.status).send(err);
});
});
// launch the server
app.listen(3000);
Smell that? That's the aroma of success! After I've gone through the process of logging in, I get my call back and it looks like this:
{
"user":{
"age":22,
"ambassador":false,
"autoStrideEnabled":true,
"avatar":"https://static0.fitbit.com/images/profile/defaultProfile_100.png",
"avatar150":"https://static0.fitbit.com/images/profile/defaultProfile_150.png",
"avatar640":"https://static0.fitbit.com/images/profile/defaultProfile_640.png",
"averageDailySteps":5296,
"clockTimeDisplayFormat":"12hour",
"corporate":false,
"corporateAdmin":false,
"dateOfBirth":"1983-08-26",
"displayName":"Bruce G.",
"displayNameSetting":"name",
"distanceUnit":"en_US",
"encodedId":"7V335V",
"familyGuidanceEnabled":false,
"features":{
"exerciseGoal":true
},
"firstName":"Bruce",
"foodsLocale":"en_US",
"fullName":"Bruce Gust",
"gender":"MALE",
"glucoseUnit":"en_US",
"height":175.20000000000002,
"heightUnit":"en_US",
"isChild":false,
"isCoach":false,
"lastName":"Gust",
"locale":"en_US",
"memberSince":"2019-10-22",
"mfaEnabled":false,
"offsetFromUTCMillis":-21600000,
"startDayOfWeek":"SUNDAY",
"strideLengthRunning":95.60000000000001,
"strideLengthRunningType":"default",
"strideLengthWalking":72.7,
"strideLengthWalkingType":"default",
"swimUnit":"en_US",
"timezone":"America/Chicago",
"topBadges":[
{
"badgeGradientEndColor":"00D3D6",
"badgeGradientStartColor":"007273",
"badgeType":"DAILY_STEPS",
"category":"Daily Steps",
"cheers":[
],
"dateTime":"2019-11-04",
"description":"15,000 steps in a day",
"earnedMessage":"Congrats on earning your first Urban Boot badge!",
"encodedId":"228TMK",
"image100px":"https://static0.fitbit.com/images/badges_new/100px/badge_daily_steps15k.png",
"image125px":"https://static0.fitbit.com/images/badges_new/125px/badge_daily_steps15k.png",
"image300px":"https://static0.fitbit.com/images/badges_new/300px/badge_daily_steps15k.png",
"image50px":"https://static0.fitbit.com/images/badges_new/badge_daily_steps15k.png",
"image75px":"https://static0.fitbit.com/images/badges_new/75px/badge_daily_steps15k.png",
"marketingDescription":"You've walked 15,000 steps And earned the Urban Boot badge!",
"mobileDescription":"With a number that's almost three times more than the national average, your step count is really heating up.",
"name":"Urban Boot (15,000 steps in a day)",
"shareImage640px":"https://static0.fitbit.com/images/badges_new/386px/shareLocalized/en_US/badge_daily_steps15k.png",
"shareText":"I took 15,000 steps and earned the Urban Boot badge! #Fitbit",
"shortDescription":"15,000 steps",
"shortName":"Urban Boot",
"timesAchieved":1,
"value":15000
},
{
"badgeGradientEndColor":"38D7FF",
"badgeGradientStartColor":"2DB4D7",
"badgeType":"DAILY_FLOORS",
"category":"Daily Climb",
"cheers":[
],
"dateTime":"2019-11-04",
"description":"50 floors in a day",
"earnedMessage":"Congrats on earning your first Lighthouse badge!",
"encodedId":"228TT7",
"image100px":"https://static0.fitbit.com/images/badges_new/100px/badge_daily_floors50.png",
"image125px":"https://static0.fitbit.com/images/badges_new/125px/badge_daily_floors50.png",
"image300px":"https://static0.fitbit.com/images/badges_new/300px/badge_daily_floors50.png",
"image50px":"https://static0.fitbit.com/images/badges_new/badge_daily_floors50.png",
"image75px":"https://static0.fitbit.com/images/badges_new/75px/badge_daily_floors50.png",
"marketingDescription":"You've climbed 50 floors to earn the Lighthouse badge!",
"mobileDescription":"With a floor count this high, you're a beacon of inspiration to us all!",
"name":"Lighthouse (50 floors in a day)",
"shareImage640px":"https://static0.fitbit.com/images/badges_new/386px/shareLocalized/en_US/badge_daily_floors50.png",
"shareText":"I climbed 50 flights of stairs and earned the Lighthouse badge! #Fitbit",
"shortDescription":"50 floors",
"shortName":"Lighthouse",
"timesAchieved":1,
"value":50
}
],
"waterUnit":"en_US",
"waterUnitName":"fl oz",
"weight":81.6,
"weightUnit":"en_US"
}
}
Outstanding! But...
If I want heart beat or activity log, I'm stuck because all I've got here is profile info.
According to https://dev.fitbit.com/build/reference/web-api/user/, I can get everything that I need, but I need the "client-id..."
GET https://api.fitbit.com/1/user/[user-id]/profile.json
According to this site, the user-id is something I can access from the profile end point, but I don't see it anywhere in the json that gets returned when I ask specifically for "profile.json" (the json that I've got above).
So,, my question is: Where do I get the client-id from? Every URL that contains the info I need requires that piece of info and I'm thinking that someone who's worked with the Fitbit API probably knows exactly where I need to be looking.
Thoughts?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
BOOM!
welcome
ASKER
Good thing it didn't bite!
Thanks Gertone!